/
githubmirror
/
LeetCode-Go
Обзор
Документация
Войти
/
githubmirror
/
LeetCode-Go
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
Special
leetcode/0028.Implement-strStr/28. Implement strStr().go
25 строк
399 B
YDZ
规范格式
07 авг 2020, 12:06
07 авг 2020, 12:06
4e11f40
Код
Авторство
О чём код?
package leetcode import "strings" // 解法一 func strStr(haystack string, needle string) int { for i := 0; ; i++ { for j := 0; ; j++ { if j == len(needle) { return i } if i+j == len(haystack) { return -1 } if needle[j] != haystack[i+j] { break } } } } // 解法二 func strStr1(haystack string, needle string) int { return strings.Index(haystack, needle) }