Skip to content

Commit d1c738c

Browse files
committed
feat: add 028
1 parent f23b6af commit d1c738c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

note/028/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ Returns the index of the first occurrence of needle in haystack, or -1 if needle
1111

1212
## 思路
1313

14-
题意是从主串中找到子串的索引,如果找不到则返回-1,我们只需要遍历主串长度减字串长度即可,利用substring比较即可。
14+
题意是从主串中找到子串的索引,如果找不到则返回-1,我们只需要遍历主串长度减子串长度即可,利用substring比较即可。
1515

1616
``` java
1717
public class Solution {
1818
public int strStr(String haystack, String needle) {
1919
int l1 = haystack.length(), l2 = needle.length(), l3 = l1 - l2;
20-
int l3 = l1 - l2;
2120
for (int i = 0; i <= l3; ++i) {
2221
if (haystack.substring(i, i + l2).equals(needle)) {
2322
return i;

0 commit comments

Comments
 (0)