Remove Invalid Parentheses
来源:互联网 发布:java服务器高并发 编辑:程序博客网 时间:2024/06/05 10:53
public class Solution { int max = 0; public List<String> removeInvalidParentheses(String s) { if (s == null) { throw new IllegalArgumentException("haha"); } List<String> res = new LinkedList<>(); helper(res, s, "", 0, 0); if (res.size() == 0) { res.add(""); } return res; } private void helper(List<String> res, String left, String right, int leftCount, int leftMax) { if (left.length() == 0) { if (leftCount == 0 && right.length() > 0) { if (leftMax > max) { max = leftMax; } if (leftMax == max && !res.contains(right)) { res.add(right); } } return; } if (left.charAt(0) == '(') { helper(res, left.substring(1), right + '(', leftCount + 1, leftMax + 1); helper(res, left.substring(1), right, leftCount, leftMax); } else if (left.charAt(0) == ')') { if (leftCount > 0) { helper(res, left.substring(1), right + ')', leftCount - 1, leftMax); } helper(res, left.substring(1), right, leftCount, leftMax); } else { helper(res, left.substring(1), right + left.charAt(0), leftCount, leftMax); } }}
0 0
- [LeetCode] Remove Invalid Parentheses
- LeetCode -- Remove Invalid Parentheses
- Remove Invalid Parentheses--Nice
- Remove Invalid Parentheses
- leetcode Remove Invalid Parentheses
- Leetcode214: Remove Invalid Parentheses
- LeetCode Remove Invalid Parentheses
- [Leetcode]Remove Invalid Parentheses
- 301. Remove Invalid Parentheses
- leetcode:Remove Invalid Parentheses
- leetcode - Remove Invalid Parentheses
- Remove Invalid Parentheses
- 【Leetcode】Remove Invalid Parentheses
- LeetCode:Remove Invalid Parentheses
- Remove Invalid Parentheses
- Remove Invalid Parentheses
- 301. Remove Invalid Parentheses
- Remove Invalid Parentheses
- 资料库:用CSDN-markdown编辑器写博客
- 归并排序
- [Leetcode]345. Reverse Vowels of a String
- js项目实战(弹性预算规则)
- HttpClient+Gson解析中国天气网的天气预报信息
- Remove Invalid Parentheses
- 【51Nod 1239】欧拉函数之和
- RMQ+二分 - CF 689D Friends and Subsequences
- JavaScript-Array 对象及方法(下)
- HDU 2825(Wireless Password-AC自动机+状压dp)
- 关于stc51的冷启动下载和复位
- AsyncHttp+gson解析
- 2016sdau课程练习专题三 1011
- Windows+Visual Studio下生成g2o库教程(结合Cholmod库)