-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexof.py
39 lines (35 loc) · 1.03 KB
/
indexof.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
__author__ = 'gaochenchao'
class Solution(object):
def indexOf(self, heack, needle):
if len(needle) == 0:
return True
for i in range(0, len(heack)):
count = 0
m = i
for j in range(0, len(needle)):
if heack[m] == needle[j]:
count += 1
m += 1
if count == len(needle):
return i
else:
break
return -1
def indexOf02(self, heack, needle):
x = len(heack)
y = len(needle)
for i in range(0, x):
count = 0
for j in range(0, y):
if i + j > x:
break
if heack[i+j] != needle[j]:
break
else:
count += 1
if count == y:
return i
return -1
print Solution().indexOf("helloworld", "ow")
print Solution().indexOf02("helloworld", "ow")