📅  最后修改于: 2022-03-11 14:55:50.004000             🧑  作者: Mango
import java.util.HashSet;
import java.util.Set;
public class BalancedParanthesis {
public static void main(String args[]){
int noOfBrackets = 3;
HashSet hs=new HashSet(generate(noOfBrackets));
System.out.println(hs);
}
public static HashSet generate(int in)
{
HashSet hs= new HashSet();
if(in ==1)
{
hs.add("()");
return hs;
}
else{
Set ab=generate(in-1);
for(String each:ab)
{
hs.add("("+each+")");
hs.add("()"+each);
hs.add(each+"()");
}
return hs;
}
}
}