本文主要是介绍Leetcode 1190. Reverse Substrings Between Each Pair of Parentheses [Python],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
考察stack的典型题目。
class Solution:def reverseParentheses(self, s: str) -> str:stack = []temp = [] def reverse(string):res = []for i in range(len(string)-1, -1, -1):res.append(string[i])return ''.join(res) for index, char in enumerate(s):if char != ")":stack.append(char)if char == ')':while stack and stack[-1] != '(':temp.append(stack.pop(-1))stack.pop() #"closest '('"while temp:stack.append(temp.pop(0))return''.join(stack)
这篇关于Leetcode 1190. Reverse Substrings Between Each Pair of Parentheses [Python]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!