Skip to content

Instantly share code, notes, and snippets.

@kigold
Created August 4, 2016 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kigold/34fc0107d14a79f5b8064c9b44651053 to your computer and use it in GitHub Desktop.
Save kigold/34fc0107d14a79f5b8064c9b44651053 to your computer and use it in GitHub Desktop.
def chkSqe(a1, a2):
'''
this method receive two array on characters, a1, and a2
it checks array a1 is the sequence of character in a2 exist
in the order, and returns true is so, or false if not
Args: a1: array of characters
a2: array of characters
Return: Boolean
'''
char_to_chk = 0
for i in range(len(a1)):
#check if the length of a1 remaining is more than the length of
#the remaining sequence
if (len(a2) - char_to_chk) > len(a1[i:]):
break
if a1[i] == a2[char_to_chk]:
if char_to_chk == len(a2) - 1:
return True
if char_to_chk + 1 < len(a2):
char_to_chk += 1
continue
else:
char_to_chk = 0
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment