""" 给你两个字符串 haystack 和 needle , 请你在 haystack 字符串中找出 needle 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回 -1 。 """
class Solution: def strStr(self, haystack: str, needle: str) -> int: if haystack==needle=='': return 0 length = len(needle) for i in range(len(haystack)): if haystack[i:i+length] == needle: return i return -1 haystack = "" needle = "" S = Solution() result = S.strStr(haystack,needle) print(result)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)