您的位置:首页 > 编程语言 > Python开发

<LeetCode><Easy> 28 Remove Element

2015-10-17 14:30 501 查看
Implement strStr().

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

#Python2  36ms

class Solution(object):
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
ne,ha=len(needle),len(haystack)
if ne>ha:return -1
for i in range(ha-ne+1):
if haystack[i:i+ne]==needle:return i
return -1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode python