Created
November 5, 2017 09:56
-
-
Save jerrypy/e5687ecbcfc86892825932ceeb675bed to your computer and use it in GitHub Desktop.
MIT 6.00 Assignments solution
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 subStringMatchExact(target, key): | |
idx = 0 | |
res = () | |
while True: | |
new_idx = target.find(key, idx) | |
if new_idx < 0: | |
return res | |
else: | |
idx = new_idx + 1 | |
res += (new_idx, ) | |
# This recursive solution is incorrect! | |
# the answer is (5, 9) which 9 should plus 5 + 1 for the correct answer | |
# | |
# def subStringMatchExactRecursive(target, key): | |
# new_idx = target.find(key) | |
# if new_idx < 0: | |
# return () | |
# else: | |
# return (new_idx, ) + subStringMatchExactRecursive(target[new_idx + 1:], key) | |
print(subStringMatchExact("atgacatgcacaagtatgcat", "atgc")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment