Finding all combinations of well-formed brackets

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

    Provider C# version based on recursive backtracking algorithm, hope it's helpful.

    public List generateParenthesis(int n) {
       List result = new LinkedList();
       Generate("", 0, 0, n, result);
       return result;
    }
    
    private void Generate(String s, int l, int r, int n, List result){
       if(l == n && r == n){
           result.add(s);
           return;
       }
    
       if(l

提交回复
热议问题