← 返回 bloomberg 的题目列表Remove Invalid Parentheses (Minimum Removal, Return All Valid Strings)
类型:online_judge
Given a string s containing only '(', ')', and letters (or general non-parenthesis characters).
Remove the minimum number of parentheses so that the resulting string has valid parentheses (properly matched and ordered). Return all possible results with no duplicates. Output order does not matter.
A string has valid parentheses if:
For every prefix, the number of '(' is at least the number of ')';
Overall counts of '(' and ')' are equal.
I/O
Input: one line string s
Output: a JSON array (or multiple lines) of all valid strings after minimum removals.
Constraints
1 <= len(s) <= 25
You may delete only parenthesis characters ( or ).
Examples
"()())()" → ["()()()","(())()"]
"(a)())()" → ["(a)()()","(a())()"]
")(" → [""]
"n" → ["n"]
"(((k))" → ["((k))"]
Example
Input
()())()
Output
["()()()","(())()"]