Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def backspaceCompare(self, S: str, T: str) -> bool:
- i,j = len(S) - 1, len(T) - 1
- while i >= 0 or j >= 0:
- hash1 = hash2 = 0
- while i >= 0 and (hash1 > 0 or S[i] == '#'): hash1, i = hash1 + 2*(S[i] == '#') - 1, i-1
- while j >= 0 and (hash2 > 0 or T[j] == '#'): hash2, j = hash2 + 2*(T[j] == '#') - 1, j-1
- if i < 0 or j < 0 or S[i] != T[j]: return i < 0 and j < 0
- i,j = i-1, j-1
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement