public class Solution {
public List<String> validParentheses(int l, int m, int n) {
// Write your solution here
int targetLen = (l + m + n) * 2;
StringBuilder curr = new StringBuilder();
List<String> res = new ArrayList<>();
Deque<Character> stack = new LinkedList<>();
char[] ps = new char[] {'(', ')', '<', '>', '{', '}'};
int[] remain = new int[] {l, l, m, m, n, n};
helper(ps, remain, targetLen, stack, curr, res);
return res;
}
private void helper(char[] ps, int[] remain, int targetLen, Deque<Character> stack, StringBuilder curr, List<String> res){
if(curr.length() == targetLen){
res.add(curr.toString());
return;
}
for(int i = 0; i < ps.length; i++){
// Pick up a left parenthesis
if(i % 2 == 0){
if(remain[i] >
LaiCode 179. All Valid Permutations Of Parentheses II
最新推荐文章于 2021-07-01 09:05:08 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)