Skip to content

Commit 74f8342

Browse files
authored
Merge pull request gzc426#5 from gzc426/master
1
2 parents 463d3aa + a46a1d0 commit 74f8342

Some content is hidden

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

90 files changed

+1764
-20
lines changed
File renamed without changes.

2019.11.24/Felix.md renamed to 2018.11.19-leetcode15/Felix.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
```
12
import java.util.Arrays;
23
34
/**
@@ -28,3 +29,4 @@ public class ThreeSumClosest {
2829
return res;
2930
}
3031
}
32+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
leetcode of 15
2+
```
3+
class Solution {
4+
public:
5+
vector<vector<int>> threeSum(vector<int>& nums) {
6+
7+
vector<vector<int>> res;
8+
if(nums.size()==0) return res;
9+
sort(nums.begin(),nums.end());
10+
int i=0;
11+
int p=0;
12+
int q=0;
13+
while(i<nums.size()-2){
14+
if(i>0 &&nums[i-1]==nums[i]){
15+
i++;
16+
continue;
17+
}
18+
if(nums[i]>0) break;
19+
int diff=0-nums[i];
20+
p=i+1;
21+
q=nums.size()-1;
22+
while(p<q){
23+
if(nums[p]+nums[q]<diff && p<q) p++;
24+
if(nums[p]+nums[q]>diff && p<q) q--;
25+
else if(p<q && nums[p]+nums[q]==diff){
26+
vector<int>temp;
27+
temp.push_back(nums[i]);
28+
temp.push_back(nums[p]);
29+
temp.push_back(nums[q]);
30+
res.push_back(temp);
31+
p++;
32+
q--;
33+
while(p<q &&nums[p]==nums[p-1]){
34+
p++;
35+
}
36+
while(p<q &&nums[q]==nums[q+1]){
37+
q--;
38+
}
39+
}
40+
}
41+
i++;
42+
}
43+
return res;
44+
}
45+
};
46+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
public int strStr(String haystack, String needle) {
3+
if(needle.length()==0){
4+
return 0;
5+
}
6+
char [] hay=haystack.toCharArray();
7+
char [] nde=needle.toCharArray();
8+
9+
for(int i=0;i<hay.length;i++){
10+
11+
if(hay[i]==nde[0]){ //遇到相同的情况
12+
int j=i+1;//指针j比较i的下一个元素与needle是否相同
13+
int k=1; //指针k遍历needle数组,从第二个开始比较,第一个已经判断相同的情况下才进入的。
14+
for(;k<nde.length&&j<hay.length;k++){
15+
if(hay[j]==nde[k]){//如果下一个元素还相同
16+
j++; //则比较haystack的下一个
17+
}else{
18+
break;//很快遇到不同的则退出。
19+
}
20+
}
21+
if(k==nde.length){
22+
return i;
23+
}
24+
}
25+
}
26+
27+
return -1;
28+
29+
}
30+
}
File renamed without changes.

0 commit comments

Comments
 (0)