Skip to content

Commit 2dd16af

Browse files
committedMay 22, 2019
2019-5-23
1 parent d9c000b commit 2dd16af

File tree

112 files changed

+2473
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2473
-0
lines changed
 
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
12+
ListNode* res = new ListNode(-1);
13+
ListNode* cur = res;
14+
int carry = 0;
15+
while(l1 || l2){
16+
int t1 = l1? l1->val : 0;
17+
int t2 = l2? l2->val : 0;
18+
int sum = t1 + t2 + carry;
19+
carry = sum / 10;
20+
cur->next = new ListNode(sum % 10);
21+
cur = cur->next;
22+
if (l1) l1 = l1->next;
23+
if (l2) l2 = l2->next;
24+
}
25+
if (carry) cur->next =new ListNode(1);
26+
return res->next;
27+
28+
29+
}
30+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
int lengthOfLongestSubstring(string s) {
4+
5+
string dic = "";
6+
int ans = 0;
7+
int i = 0;
8+
int j = 0;
9+
int l = s.size();
10+
while( i < l && j < l ){
11+
char a = s[i];
12+
char b = s[j];
13+
// cout<<dic.find(b)<<endl;
14+
if (dic.find(b) >= 0 && dic.find(b) < 99999999){
15+
i += 1;
16+
dic.erase(0, 1);
17+
}
18+
else{
19+
j += 1;
20+
dic.push_back(b);
21+
// cout << "Dasdas" << endl;
22+
}
23+
ans = ans < j-i ? j-i : ans;
24+
// cout <<i<<" "<<j << endl;
25+
}
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
 (0)