思路:用find函数找位置,分三种情况,找到,输出下标,找不到输出-1,为空输出0.
原题如下:
通过解答如下:
class Solution(object):
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
a = 0
if needle in haystack:
a = haystack.find(needle)
else:
a = -1
if needle == '':
a = 0
return a