SRM597 Dic2 Medium
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
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