LeetCode-28. Implement strStr()
2018-03-25 10:18
387 查看
题目:
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"
Output: 2
Example 2:Input: haystack = "aaaaa", needle = "bba"
Output: -1
solution:
class Solution:
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
if needle not in haystack:
return -1
else:
return haystack.index(needle)
No more words
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"
Output: 2
Example 2:Input: haystack = "aaaaa", needle = "bba"
Output: -1
solution:
class Solution:
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
if needle not in haystack:
return -1
else:
return haystack.index(needle)
No more words
相关文章推荐
- 小白笔记-----------------------leetcode(28. Implement strStr())
- LeetCode - 28. Implement strStr()
- leetcode 28. Implement strStr()
- [勇者闯LeetCode] 28. Implement strStr()
- leetcode-28. Implement strStr()
- leetcode 28. Implement strStr()
- 【LeetCode】28. Implement strStr() (2 solutions)
- 个人记录-LeetCode 28. Implement strStr()
- LeetCode 28. Implement strStr()
- Leetcode-28. Implement strStr()
- [LeetCode] 28. Implement strStr() ☆
- [leetcode]28. Implement strStr()
- [leetcode] 28. Implement strStr()
- [leetcode]28. Implement strStr()
- Leetcode 28. Implement strStr()
- [LeetCode]28. Implement strStr()
- LeetCode-28. Implement strStr()
- LeetCode 28. Implement strStr()(实现子串定位)
- LeetCode 28. Implement strStr()
- LeetCode28. Implement strStr()