作者DJYOMIYAHINA (通通打死)
標題Re: [閒聊] 每日leetcode
時間2024-07-11 08:36:51
好像就先用stack照做
不知道有沒有其他騷作法
有空來看看
def reverseParentheses(self, s: str) -> str:
stk = []
for c in s:
if c == ")":
tmp = []
while stk[-1] != "(":
tmp.append(stk.pop())
stk.pop()
stk += tmp
else:
stk.append(c)
return "".join(stk)
--
※ 發信站: 批踢踢實業坊(ptt.org.tw), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://ptt.org.tw/Marginalman/M.1720658213.A.6CD
推 smart0eddie: 大師 07/11 08:38
→ DJYOMIYAHINA: 我看到O(N)的作法了 點點點 07/11 08:39
→ SecondRun: 大師 07/11 08:40
→ rainkaras: 通勤刷題大師 07/11 08:43