Created
July 10, 2012 09:41
-
-
Save shawnchin/3082329 to your computer and use it in GitHub Desktop.
pseudocode of answer for SO question 11409942
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
# http://stackoverflow.com/questions/11409942/function-subseq-python-need-thoughts | |
function is_sub(s1, s2): | |
let L1 be the length of s1 and L2 the length of s2 | |
1. if L2 > L1, s2 is definitely not a subset of s1, so return False | |
2. if the first L2 elements in s1 equals to s2, then s2 is a subset. return True. | |
3. otherwise, make a recusive call to determine if s2 is a subset of s1[1:] and return the result. | |
p.s. You might find the slice notation useful. See http://stackoverflow.com/a/509295/115845 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment