forked from ssjssh/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.py
More file actions
30 lines (23 loc) · 738 Bytes
/
simple.py
File metadata and controls
30 lines (23 loc) · 738 Bytes
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
#!/usr/bin/env python
# -*- coding:UTF-8
__author__ = 'shenshijun'
def match(origin, pattern):
origin_index, pattern_index = 0, 0
match_flag = True
pattern_len = len(pattern)
while origin_index < len(origin):
for pattern_index in xrange(pattern_len):
if pattern[pattern_index] != origin[origin_index]:
origin_index -= (pattern_index - 1)
match_flag = False
break
else:
origin_index += 1
pattern_index += 1
match_flag = True
if match_flag:
return origin_index - pattern_index
def main():
print match("absabsvbshsbdhhd", 'sb')
if __name__ == "__main__":
main()