def dfs(self, s, cur, left, pi, i, rmcnt, ret):
        """
        Remove parenthesis
        backtracking, post-check
        :param s: original string
        :param cur: current string builder
        :param left: number of remaining left parentheses in s[0..i] not consumed by ")"
        :param pi: last removed char
        :param i: current index
        :param rmcnt: number of remaining removals needed
        :param ret: results
        """
        if left < 0 or 0 < rmcnt or i > len(s):
            return
        if i == len(s):
            if rmcnt == 0 and left == 0:
                ret.append(cur)
            return

        if s[i] not in ("(", ")"):  # skip non-parenthesis
            self.dfs(s, cur+s[i], left, None, i+1, rmcnt, ret)
        else:
            if pi == s[i]:  # jump, if rm, rm them all to avoid duplication
                while i < len(s) and pi and pi == s[i]: i, rmcnt = i+1, rmcnt-1
                self.dfs(s, cur, left, pi, i, rmcnt, ret)
            else:
                self.dfs(s, cur, left, s[i], i+1, rmcnt-1, ret)
                L = left+1 if s[i] == "(" else left-1  # consume "("
                self.dfs(s, cur+s[i], L, None, i+1, rmcnt, ret)  # put
dataset/ETHPy150Open algorhythms/LeetCode/301 Remove Invalid Parentheses.py/Solution.dfs/swapped operands of `<`