301. Remvoe Invalid Parenthesis
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)
.
Example 1:
Example 2:
Example 3:
Facebook Variation: any solution that results in minimum removal of parentheses
Thoughts: 楼主用了一个3-pass的方法: 先从头到尾找close比open多的,移掉; 从尾到头找open比close多的,移掉; 然后最后一遍build
Thoughts:
Expanding the set and test whether each combination is valid, once there is answer in the set , then return (we want the minimum edition)
Code: Python
Last updated
Was this helpful?