Last active
December 11, 2018 05:10
-
-
Save jovianlin/36e4c15e69c17df4b4f7a1221c9ccd28 to your computer and use it in GitHub Desktop.
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 Solution: | |
def backspaceCompare(self, S, T): | |
""" | |
:type S: str | |
:type T: str | |
:rtype: bool | |
""" | |
pointerS, pointerT = len(S)-1, len(T)-1 | |
skipS, skipT = 0, 0 | |
while pointerS >= 0 or pointerT >= 0: | |
while pointerS >= 0 and S[pointerS] == '#': | |
skipS += 1 | |
pointerS -= 1 | |
while pointerS >= 0 and skipS > 0 and S[pointerS] != '#': | |
pointerS -= 1 | |
skipS -= 1 | |
while pointerT >= 0 and T[pointerT] == '#': | |
skipT += 1 | |
pointerT -= 1 | |
while pointerT >= 0 and skipT > 0 and T[pointerT] != '#': | |
pointerT -= 1 | |
skipT -= 1 | |
if pointerS >= 0 or pointerT >= 0: | |
if S[pointerS] == T[pointerT]: | |
pointerS -= 1 | |
pointerT -= 1 | |
else: | |
return False | |
# End of while loop | |
if pointerS == pointerT: | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment