Finding all combinations of well-formed brackets

后端 未结 29 1641
盖世英雄少女心
盖世英雄少女心 2020-11-28 02:34

This came up while talking to a friend and I thought I\'d ask here since it\'s an interesting problem and would like to see other people\'s solutions.

The task is to

29条回答
  •  青春惊慌失措
    2020-11-28 02:51

    Another inefficient but elegant answer =>

    public static Set permuteParenthesis1(int num)
    {   
        Set result=new HashSet();
        if(num==0)//base case
            {
                result.add("");
                return result;
            }
        else
            {
                Set temp=permuteParenthesis1(num-1); // storing result from previous result.
                for(String str : temp)
                {
                    for(int i=0;i

提交回复
热议问题