Created
November 5, 2017 09:56
-
-
Save jerrypy/2ce3d0769bc013d83b148a9e9dbd13a9 to your computer and use it in GitHub Desktop.
MIT 6.00 Assignments soluntion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def countSubStringMatch(target, key): | |
count = 0 | |
idx = 0 | |
while True: | |
new_idx = target.find(key, idx) | |
if new_idx < 0: | |
return count | |
else: | |
count += 1 | |
idx = new_idx + 1 | |
def countSubStringMatchRecursive(target, key): | |
new_idx = target.find(key) | |
if new_idx < 0: | |
return 0 | |
else: | |
return countSubStringMatchRecursive(target[new_idx + 1:], key) + 1 | |
print(countSubStringMatch("atgacatgcacaagtatgcat", "atgc")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment