class Solution:
def strStr(self, haystack: str, needle: str) -> int:
# if haystack == needle:
# return 0
# len_n = len(needle)
# for i in range(len(haystack)):
# if haystack[i:i+len_n] == needle:
# return i
# return -1
try:
return haystack.index(needle)
except Exception:
return -1
28,实现strStr
最新推荐文章于 2024-04-29 20:59:36 发布