8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d4adf9e commit 0596ba6Copy full SHA for 0596ba6
leetcode/ImplementstrStr.py
@@ -0,0 +1,29 @@
1
+#-*- coding:utf-8 -*-
2
+'''
3
+Created on 2017年4月19日
4
+
5
+@author: huangjiaxin
6
7
+class Solution(object):
8
+ def strStr(self, haystack, needle):
9
+ """
10
+ :type haystack: str
11
+ :type needle: str
12
+ :rtype: int
13
14
+ hlen, nlen = len(haystack), len(needle)
15
+ if nlen == 0:
16
+ return 0
17
+ if hlen == 0 or hlen < nlen:
18
+ return -1
19
+ for i in range(hlen - nlen + 1):
20
+ if haystack[i:i+nlen] == needle:
21
+ return i
22
23
24
25
+if __name__ == '__main__':
26
+ haystack = ''
27
+ needle = ''
28
+ print Solution().strStr(haystack, needle)
29
0 commit comments