Easy
Last updated 4 years ago
Was this helpful?
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.
class Solution: def backspaceCompare(self, S: str, T: str) -> bool: temp_s = '' temp_t = '' for i,s in enumerate(S): if S[i] == '#': temp_s = temp_s[:-1] else: temp_s += s for j,t in enumerate(T): if T[j] == '#': temp_t = temp_t[:-1] else: temp_t += t return temp_s == temp_t