给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。若是不存在,则返回 -1。网络
示例 1: 输入: haystack = "hello", needle = "ll" 输出: 2 示例 2: 输入: haystack = "aaaaa", needle = "bba" 输出: -1
class Solution: def strStr(self, haystack: str, needle: str) -> int: if needle in haystack: return haystack.index(needle) else: return -1
笨办法,若是needle存在与hastack中,根据index方法获取下表位置,不然返回-1code
来源:力扣(LeetCode)
连接:https://leetcode-cn.com/problems/design-circular-queue
著做权归领扣网络全部。商业转载请联系官方受权,非商业转载请注明出处。ci