File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding:UTF-8
3
+ __author__ = 'shenshijun'
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding:UTF-8
3
+ __author__ = 'shenshijun'
4
+
5
+
6
+ def match (origin , pattern ):
7
+ origin_index , pattern_index = 0 , 0
8
+ pattern_len = len (pattern )
9
+ while origin_index < len (origin ):
10
+ for pattern_index in xrange (pattern_len ):
11
+ if pattern [pattern_index ] != origin [origin_index ]:
12
+ origin_index -= (pattern_index - 1 )
13
+ break
14
+ else :
15
+ origin_index += 1
16
+ pattern_index += 1
17
+
18
+ if origin [origin_index ] == pattern [pattern_index ]:
19
+ return origin_index - pattern_index
20
+
21
+
22
+ def main ():
23
+ print match ("absbsbshdhhd" , 'sb' )
24
+
25
+
26
+ if __name__ == "__main__" :
27
+ main ()
You can’t perform that action at this time.
0 commit comments