Remove Invalid Parentheses
来源:互联网 发布:淘宝账户余额怎么充值 编辑:程序博客网 时间:2024/06/13 22:12
public class Solution { int max = 0; public List<String> removeInvalidParentheses(String s) { 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 maxCount) { if (left.length() == 0) { if (leftCount == 0 && right.length() != 0) { if (maxCount > max) { max = maxCount; } if (maxCount == max && !res.contains(right)) { res.add(right); } } return; } if (left.charAt(0) == '(') { helper(res, left.substring(1), right + '(', leftCount + 1, maxCount + 1); helper(res, left.substring(1), right, leftCount, maxCount); } else if (left.charAt(0) == ')') { if (leftCount > 0) { helper(res, left.substring(1), right + ')', leftCount - 1, maxCount); } helper(res, left.substring(1), right, leftCount, maxCount); } else { helper(res, left.substring(1), right + left.charAt(0), leftCount, maxCount); } }}
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
- MySql数据库相关基础知识
- 多图片展示及运动框架总结
- 用Orcad做原理图,用PADS layout(转)
- Merge Intervals
- Android Studio 真正国内SDK在线更新说明
- Remove Invalid Parentheses
- 读《张爱玲:她从海上来》有感
- Reverse Linked List
- Minimum Window Substring
- 【9409】集合的划分问题
- [初学Unity]Graphics-02.Rendering and Shading
- 雾雨魔理沙
- JavaScript查找奇偶异常值
- 提示框