-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDayNine_backspaceCompare
More file actions
36 lines (31 loc) · 887 Bytes
/
Copy pathDayNine_backspaceCompare
File metadata and controls
36 lines (31 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution(object):
def backspaceCompare(self, S, T):
"""
:type S: str
:type T: str
:rtype: bool
"""
s1 = []
s2 =[]
for char in range(len(S)):
if S[char] !="#":
s1.append(S[char])
else:
if not s1:
char = char+1
else:
s1.pop()
for char in range(len(T)):
if T[char] != "#":
s2.append(T[char])
else:
if not s2:
char = char +1
else:
s2.pop()
if s1==s2:
print(True)
else:
print(False)
m = Solution()
m.backspaceCompare("ab#c", "ad#c")