Skip to content

Commit 86225d7

Browse files
authored
Merge pull request #1 from gzc426/master
pull request
2 parents 036c275 + ccfe23f commit 86225d7

File tree

149 files changed

+4467
-18
lines changed

Some content is hidden

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

149 files changed

+4467
-18
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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+
```

2018.11.24-leetcode28/ELF

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int strStr(String haystack, String needle) {
3+
if (needle.length() ==0 )
4+
return 0;
5+
for (int i = 0;i<haystack.length();i++){
6+
if (haystack.charAt(i) == needle.charAt(0)){
7+
int j =i+1;
8+
int k =1;
9+
for (k =1;k<needle.length()&&j<haystack.length();k++){
10+
if (haystack.charAt(j) == needle.charAt(k))
11+
j++;
12+
else
13+
break;
14+
15+
}
16+
if (k == needle.length())
17+
return i;
18+
}
19+
}
20+
return -1;
21+
}
22+
}

2018.11.24-leetcode28/TheRocket

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```java
2+
class Solution {
3+
public int strStr(String haystack, String needle) {
4+
if (needle.length() == 0) {
5+
return 0;
6+
}
7+
int max = haystack.length() - needle.length();
8+
for (int i = 0; i <= max; ++i) {
9+
// 找到第一个相等的字符
10+
if (haystack.charAt(i) == needle.charAt(0)) {
11+
int j = i + 1;
12+
for (int k = 1; k < needle.length()
13+
&& haystack.charAt(j) == needle.charAt(k); ++k, ++j);
14+
// 找到整个字符串就返回
15+
if (j == i + needle.length()) {
16+
return i;
17+
}
18+
}
19+
}
20+
return -1;
21+
}
22+
}
23+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
```
2+
class Solution {
3+
public int strStr(String haystack, String needle) {
4+
int len = haystack.length();
5+
int sublen = needle.length();
6+
for (int i = 0; i < len - sublen + 1; i++){
7+
if (haystack.substring(i, i + sublen).equals(needle)){
8+
return i;
9+
}
10+
}
11+
return -1;
12+
}
13+
}
14+
```

2018.11.24-leetcode28/WhiteNight.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
>```java
2+
>/**
3+
> * 实现strStr()
4+
> *
5+
> */
6+
>public class S1 {
7+
>// public int strStr(String haystack, String needle) {
8+
>// //直接调用indexof()
9+
>// return haystack.indexOf(needle);
10+
>// }
11+
>
12+
> public int strStr(String haystack, String needle) {
13+
> if (needle.length() == 0)
14+
> return 0;
15+
>
16+
> char[] charArrayHaystack = haystack.toCharArray();
17+
> char[] charArrayNeedle = needle.toCharArray();
18+
>
19+
> for (int i = 0; i < charArrayHaystack.length; i++) {
20+
> if (charArrayHaystack[i] == charArrayNeedle[0]){
21+
> int j = i + 1;
22+
> int k = 1;
23+
> for (;k < charArrayNeedle.length && j < charArrayHaystack.length; k++) {
24+
> if (charArrayHaystack[j] == charArrayNeedle[k])
25+
> j++;
26+
> else
27+
> break;
28+
> }
29+
> if (k == charArrayNeedle.length)
30+
> return i;
31+
> }
32+
> }
33+
>
34+
> return -1;
35+
> }
36+
>
37+
> public static void main(String[] args) {
38+
> S1 s = new S1();
39+
> int res = s.strStr("hello","ll");
40+
> System.out.println(res);
41+
> }
42+
>}
43+
>```
44+

2018.11.24-leetcode28/Whits.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package AC;
2+
3+
import java.lang.reflect.Array;
4+
5+
public class leetcode_28_AC {
6+
7+
8+
9+
public static void main(String[] args) {
10+
11+
String haystack = "hello";
12+
String needle = "ll";
13+
System.out.println(strStrNew(haystack,needle));
14+
15+
}
16+
public static int strStr(String haystack, String needle) {
17+
if (needle.length()==0)
18+
return 0;
19+
char[]hayStackCharArray =haystack.toCharArray();
20+
char[]needleCharArray = needle.toCharArray();
21+
for (int i = 0; i < hayStackCharArray.length; i++) {
22+
if (hayStackCharArray[i] == needleCharArray[0]) { //第一个指针对比,若相同则进入if语句。
23+
int j = i+1; //把此时的i+1赋值给k,直接比较第二个值
24+
int k = 1; //直接比较第二个值
25+
for (; k<needleCharArray.length && j<hayStackCharArray.length; k++) {
26+
if (hayStackCharArray[j] == needleCharArray[k])
27+
j++;
28+
else {
29+
break;
30+
}
31+
}
32+
if (needleCharArray.length==k){
33+
return i;
34+
}
35+
}
36+
}
37+
return -1;
38+
}
39+
40+
public static int strStrNew(String haystack, String needle){
41+
int hayStackLength = haystack.length();
42+
int needleLength = needle.length();
43+
if (needleLength>hayStackLength) return -1; if (needleLength == 0) return 0;
44+
for (int i = 0; i<hayStackLength-needleLength;i++) {
45+
if (haystack.substring(i,needleLength+i).equals(needle))
46+
return i;
47+
}
48+
return -1;
49+
}
50+
/**
51+
* 还应该尝试下kmp算法
52+
* @author:liuquan
53+
* @date:2018/11/28 22:00
54+
* @param
55+
* @return
56+
*/
57+
58+
}
File renamed without changes.

0 commit comments

Comments
 (0)