Skip to content

Latest commit

 

History

History
23 lines (21 loc) · 558 Bytes

1190.md

File metadata and controls

23 lines (21 loc) · 558 Bytes

1190. Reverse Substrings Between Each Pair of Parentheses

Solution 1 (time O(n), space O(n))

class Solution(object):
    def reverseParentheses(self, s):
        """
        :type s: str
        :rtype: str
        """
        ans = []
        for c in s:
            if c == ')':
                t = []
                while ans[-1] != '(':
                    t.append(ans.pop())
                ans.pop()
                ans = ans + t
            else:
                ans.append(c)
        return "".join(ans)