Skip to content

Commit 315b143

Browse files
author
liwentian
committed
implement str str
1 parent 7bc68fa commit 315b143

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

‎Facebook.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ Facebook题目列表(24)
5050
|39|[Combination Sum](https://leetcode.com/problems/combination-sum/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CombinationSum.java)|
5151
|40|[Combination Sum II](https://leetcode.com/problems/combination-sum-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CombinationSumII.java)|
5252
|216|[Combination Sum III](https://leetcode.com/problems/combination-sum-iii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CombinationSumIII.java)|
53-
|377|[Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/combinationSum4.java)|
53+
|377|[Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/combinationSum4.java)|
54+
|28|[ Implement strStr()](https://leetcode.com/problems/implement-strstr/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/StrStr.java)|

‎Leetcodes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
|20|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/ValidParentheses.java)|100|
1414
|21|[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/MergeTwoSortedList.java)|90|
1515
|23|[Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/MergeKSortedList.java)|70|
16+
|28|[ Implement strStr()](https://leetcode.com/problems/implement-strstr/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/StrStr.java)|70|
1617
|38|[Count and Say](https://leetcode.com/problems/count-and-say/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CountAndSay.java)|80|
1718
|39|[Combination Sum](https://leetcode.com/problems/combination-sum/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CombinationSum.java)|70|
1819
|40|[Combination Sum II](https://leetcode.com/problems/combination-sum-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CombinationSumII.java)|70|

‎app/app.iml‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@
6666
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6767
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6868
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
75-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
76-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
7769
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
7870
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
7971
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
@@ -82,6 +74,14 @@
8274
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
8375
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
8476
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
84+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
8686
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2.2/jars" />
8787
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-idling-resource/2.2.2/jars" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.inuker.solution;
2+
3+
/**
4+
* Created by dingjikerbo on 16/11/23.
5+
*/
6+
7+
public class StrStr {
8+
9+
// 这种暴力法会超时,需要用KMP
10+
int strStr(String haystack, String needle) {
11+
int len1 = haystack.length();
12+
int len2 = needle.length();
13+
for (int i = 0; i < len1; i++) {
14+
int j = 0;
15+
for ( ; i + j < len1 && j < len2; j++) {
16+
if (haystack.charAt(i + j) != needle.charAt(j)) {
17+
break;
18+
}
19+
}
20+
if (j == len2) {
21+
return i;
22+
}
23+
}
24+
return -1;
25+
}
26+
27+
}

0 commit comments

Comments
 (0)