Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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