class Solution(object):
    def parenthesis_generator(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        result = []
        self.generator_helper([], n, n, result)
        return result

    def generator_helper(self, curr, left, right, result):
        if left == 0 and right == 0:
            result.append(''.join(curr))
            return

        if left != 0:
            curr.append('(')
            self.generator_helper(curr, left - 1, right, result)
            curr.pop()

        if right > left:
            curr.append(')')
            self.generator_helper(curr, left, right - 1, result)
            curr.pop()

solution = Solution()
print(solution.parenthesis_generator(3))