mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-25 09:50:59 -04:00
cleaning up and organizing old problems (builtin)
This commit is contained in:
parent
6afe96fa4d
commit
3fdbc2a605
106 changed files with 480 additions and 1472 deletions
36
src/builtin_structures/find_if_is_substr.py
Normal file
36
src/builtin_structures/find_if_is_substr.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "bt3"
|
||||
|
||||
|
||||
def find_substr(s1, s2):
|
||||
|
||||
if len(s1) < len(s2):
|
||||
bs = s2
|
||||
ss = s1
|
||||
else:
|
||||
bs = s1
|
||||
ss = s2
|
||||
|
||||
ps = 0
|
||||
|
||||
for c in bs:
|
||||
|
||||
if ss[ps] == c:
|
||||
ps += 1
|
||||
else:
|
||||
ps = 0
|
||||
|
||||
if ps == len(ss)-1:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
s1 = 'buffy is a vampire slayer'
|
||||
s2 = 'vampire'
|
||||
s3 = 'angel'
|
||||
assert(find_substr(s2, s1) == True)
|
||||
assert(find_substr(s3, s1) == False)
|
Loading…
Add table
Add a link
Reference in a new issue