LeetCode 筆記 - 844. Backspace String Compare

題目在此 844. Backspace String Compare

給定兩個字串,請判斷處理完退位鍵 # 是否相等

解題思維

抱歉,我不知道可以解釋什麼…

程式碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution:    
def backspaceCompare(self, s: str, t: str) -> bool:
def get_string(string: str) -> str:
while '#' in string:
index = string.find('#')
if index == 0:
string = string[1:]
else:
string = f'{string[:index - 1]}{string[index + 1:]}'

return string

s = get_string(s)
t = get_string(t)

return s == t

也許你也會想看看