Skip to content

Instantly share code, notes, and snippets.

@jerrypy
Created November 5, 2017 09:56
Show Gist options
  • Save jerrypy/2ce3d0769bc013d83b148a9e9dbd13a9 to your computer and use it in GitHub Desktop.
Save jerrypy/2ce3d0769bc013d83b148a9e9dbd13a9 to your computer and use it in GitHub Desktop.
MIT 6.00 Assignments soluntion
#!/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