Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Generate Paranthesis

     import java.util.HashSet;
     import java.util.Set;

     public class BalancedParanthesis {
       public static void main(String args[]){
         int noOfBrackets = 3;
         HashSet<String> hs=new HashSet(generate(noOfBrackets));
         System.out.println(hs);
         }
         public static HashSet<String> generate(int in)
         {
          HashSet<String> hs= new HashSet<String>();
          if(in ==1)
         {
        hs.add("()");
        return hs;
         }
        else{
           Set<String> ab=generate(in-1);
           for(String each:ab)
            {
            hs.add("("+each+")");
            hs.add("()"+each);
            hs.add(each+"()");
            }
        return hs;
         }
        }
       }
Comment

PREVIOUS NEXT
Code Example
Java :: serilize filke in java 
Java :: minecraft 21w14a bugs 
Java :: fibonacci for biginteger 
Java :: okhttp Sending and Receiving Network Requests 3 21 
Java :: picking a random string from string array java 
Java :: checkboslisttilw in flutter 
Java :: spigot change move speed of living entity creature 
Java :: java operater == char 
Java :: how to add value in jcombobox in java 
Java :: fail if condition not met in java if condition 
Java :: minecraft java plugin shift 
Java :: java create a hashmap 
Java :: encode é to é java 
Java :: android studio cannot resolve @nullable 
Java :: example of throws clause in method 
Java :: Java Generic Functional Interface 
Java :: snapshot for loop android java 
Java :: convert java code to kotlin online 
Java :: exemple javafx 
Java :: recursion java 
Java :: query spring boot 
Java :: char to charsequence in java 
Java :: Can a method be abstract and final in abstract class 
Java :: enum to string java 
Java :: button event 
Java :: android get id of view 
Java :: quit button java swing 
Java :: why does the ribbon dependency crush my app 
Sql :: find sp name by text in sql server 
Sql :: mysql add user with all privileges 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =