-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
762f0a9
commit 3b294b9
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
struct ListNode | ||
{ | ||
int val; | ||
ListNode *next; | ||
ListNode(int x) : val(x), next(NULL) {} | ||
}; | ||
|
||
ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) | ||
{ | ||
|
||
ListNode *l3 = new ListNode(0); | ||
ListNode *current = l3; | ||
int carry = 0; | ||
|
||
while (l1 != NULL || l2 != NULL || carry != 0) | ||
{ | ||
int sum = carry; | ||
if (l1 != NULL) | ||
{ | ||
sum += l1->val; | ||
l1 = l1->next; | ||
} | ||
if (l2 != NULL) | ||
{ | ||
sum += l2->val; | ||
l2 = l2->next; | ||
} | ||
carry = sum / 10; | ||
current->next = new ListNode(sum % 10); | ||
current = current->next; | ||
} | ||
|
||
return l3->next; | ||
} |
41 changes: 41 additions & 0 deletions
41
leetcode_problemset/problemsets/longest_substring_without_repeating.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
pair<int,int> check_substring(string comp, int k) { | ||
|
||
int size = comp.length(); | ||
unordered_map<char,int> rep; | ||
for(int i = k; i < size; ++i) { | ||
rep[comp[i]]++; | ||
if(rep[comp[i]] >= 2) | ||
return {k,i}; | ||
} | ||
|
||
return {k,size}; | ||
|
||
} | ||
|
||
int lengthOfLongestSubstring(string s) { | ||
|
||
int ini = 0, size = s.length(), fin = 0; | ||
for(int i = 0; i < size; ++i) { | ||
pair<int,int> new_fin = check_substring(s,i); | ||
if((new_fin.second - new_fin.first) > (fin-ini)) { | ||
fin = new_fin.second; | ||
ini = new_fin.first; | ||
} | ||
//cout << ini << " " << fin << endl; | ||
} | ||
|
||
return fin-ini; | ||
} | ||
|
||
|
||
// int main(){ | ||
|
||
// string s = "abcabcbb"; | ||
// int maxSub = lengthOfLongestSubstring(s); | ||
// cout << maxSub << endl; | ||
|
||
// return 0; | ||
// } |