码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode1190

时间:2019-09-16 00:12:53      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:for   ever   app   pop   +=   parent   tps   tco   ems   

 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

leetcode1190

标签:for   ever   app   pop   +=   parent   tps   tco   ems   

原文地址:https://www.cnblogs.com/asenyang/p/11524940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!