-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aQua
authored and
aQua
committed
Aug 1, 2017
1 parent
c0ada66
commit 829b8fc
Showing
3 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
package Problem0028 | ||
|
||
func strStr(haystack string, needle string) int { | ||
hlen, nlen := len(haystack), len(needle) | ||
// 当hlen等于nlen的时候,需要i == 0 | ||
for i := 0; i <= hlen-nlen; i++ { | ||
if haystack[i:i+nlen] == needle { | ||
return i | ||
} | ||
} | ||
|
||
return -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters