28. Implement strStr() Add to List

来源:互联网 发布:java工程师的岗位要求 编辑:程序博客网 时间:2024/06/15 21:19

Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.


code:

class Solution(object):
    def strStr(self, haystack, needle):
        """
        :type haystack: str
        :type needle: str
        :rtype: int
        """
        if needle not in haystack:return -1
        return haystack.find(needle)

原创粉丝点击