Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.
Note: The input string may contain letters other than the parentheses ( and ).1
2
3
4
5
6
7
8
9
10
11
12Example 1:
Input: "()())()"
Output: ["()()()", "(())()"]
Example 2:
Input: "(a)())()"
Output: ["(a)()()", "(a())()"]
Example 3:
Input: ")("
Output: [""]
- 从左到右检查多余的“)”,多了就要删除前面的一个“)”(条件是:不连续的就肯定可以删,连续的“)”只删除第一个,因为是一样的效果)
- 做完从左到右之后做一次从右到左,就是最后结果
- 只要一轮,不要重复
1 | class Solution { |