Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chaudharisuresh997/1654c0e48e70d0b9edb0ddc2ffa5d7ac to your computer and use it in GitHub Desktop.
Save chaudharisuresh997/1654c0e48e70d0b9edb0ddc2ffa5d7ac to your computer and use it in GitHub Desktop.
weird recursion issue
//weird recursion gen permutation paranthesis
package com.internet;
import java.util.ArrayList;
import java.util.List;
public class PintAllPermutationOfParanthesis {
public static void printAllParanthesis(List<String> finalOp, int open, int close, int n){
if(close==n){
//for(String ls:finalOp) {
finalOp.stream().forEach(System.out::print);
//finalOp.clear();
System.out.println();
//}
return;
}
else {
if (open > close) {
finalOp.add("}");
printAllParanthesis(finalOp, open, close+1, n);
}
if (open < n) {
finalOp.add("{");
printAllParanthesis(finalOp, open+1, close, n);
}
}
}
public static void main(String[] args){
PintAllPermutationOfParanthesis printPara=new PintAllPermutationOfParanthesis();
List<String> str =new ArrayList<>();
printAllParanthesis(str,0,0,3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment