Finding all combinations of well-formed brackets

后端 未结 29 1686
盖世英雄少女心
盖世英雄少女心 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 03:11

    Simple solution in C++:

    #include 
    #include 
    
    void brackets(string output, int open, int close, int pairs)
    {
        if(open == pairs && close == pairs)
                cout << output << endl;
        else
        {
                if(open

    Output:

    Combination for i = 1
    ()
    Combination for i = 2
    (())
    ()()
    Combination for i = 3
    ((()))
    (()())
    (())()
    ()(())
    ()()()
    

提交回复
热议问题