Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active December 28, 2015 21:39
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 cocodrips/7566638 to your computer and use it in GitHub Desktop.
Save cocodrips/7566638 to your computer and use it in GitHub Desktop.
SRM597 Dic2 Medium
class LittleElephantAndString:
def getNumber(self, A, B):
if sorted(A) != sorted(B):
return -1
A = list(A)[::-1]
B = list(B)[::-1]
non_move = 0
a_index = 0
b_index = 0
while(b_index < len(B) and a_index < len(A)):
while(a_index < len(A)):
if A[a_index] == B[b_index]:
non_move += 1
break
a_index += 1
b_index += 1
a_index += 1
return len(A) - non_move
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment