[LeetCode28]

来源:互联网 发布:末日战歌全套源码 编辑:程序博客网 时间:2024/06/06 02:56

字符串匹配:

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


0 0
原创粉丝点击