字符串匹配:
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Subscribe to see which companies asked this question
python实现:
class Solution(object):
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
if haystack.strip() == '' and needle.strip() =='':
return 0
if needle in haystack:
first=needle.split()[0]
return haystack.find(first)
else:
return -1