Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. class Solution:
  2.     def backspaceCompare(self, S: str, T: str) -> bool:
  3.         i,j = len(S) - 1, len(T) - 1
  4.         while i >= 0 or j >= 0:
  5.             hash1 = hash2 = 0
  6.             while i >= 0 and (hash1 > 0 or S[i] == '#'): hash1, i = hash1 + 2*(S[i] == '#') - 1, i-1
  7.             while j >= 0 and (hash2 > 0 or T[j] == '#'): hash2, j = hash2 + 2*(T[j] == '#') - 1, j-1
  8.             if i < 0 or j < 0 or S[i] != T[j]: return i < 0 and j < 0
  9.             i,j = i-1, j-1
  10.         return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement