Posted on 2023-04-11 17:41
Uriel 閱讀(39)
評論(0) 編輯 收藏 引用 所屬分類:
字符串處理 、
閑來無事重切Leet Code 、
大水題
處理一列字符串,遇到*就刪除*和左邊一個字符,輸出操作完的字符串,字符串水題
1 #2390
2 #Runtime: 311 ms (Beats 87.74%)
3 #Memory: 16.5 MB (Beats 43.40%)
4
5 class Solution(object):
6 def removeStars(self, s):
7 """
8 :type s: str
9 :rtype: str
10 """
11 ss = []
12 for ch in s:
13 if ch == '*':
14 ss.pop()
15 else:
16 ss.append(ch)
17 return ''.join(ss)