#301
Remove Invalid Parentheses
candidate master · 1430 · lc hard +32 · verified · 49.8% accepted · 6,064 likes · top 37%
Description
Given a string s containing parentheses and letters, remove the fewest parentheses necessary to make the string valid. Return all distinct valid results achievable with the minimum number of removals. The results may be returned in any order.
Example 1:
Input: s = "()())()"
Output: ["(())()","()()()"]
Example 2:
Input: s = "(a)())()"
Output: ["(a())()","(a)()()"]
Example 3:
Input: s = ")("
Output: [""]
Code
1
2
3