Created
June 24, 2019 15:55
-
-
Save chaudharisuresh997/1654c0e48e70d0b9edb0ddc2ffa5d7ac to your computer and use it in GitHub Desktop.
weird recursion issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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