leetcode1190

这一生的挚爱 提交于 2019-11-29 17:34:33
 1 class Solution:
 2     def reverseParentheses(self, s: str) -> str:
 3         stack = ['']
 4         for c in s:
 5             if c == '(':
 6                 stack.append('')
 7             elif c == ')':
 8                 add = stack.pop()[::-1]
 9                 stack[-1] += add
10             else:
11                 stack[-1] += c
12         return stack.pop()

参考:https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/discuss/382775/Python3-straightforward-and-easiest-on-discussion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!