How to print all possible balanced parentheses for an expression?

前端 未结 9 1897
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 11:41

For example, with elements a,b,c,d, there are 5 possible ways to take neighboring elements and reduce them into a single element, where exactly two elements mus

9条回答
  •  长情又很酷
    2020-12-15 11:55

    And, here is some C++ code for the same :

    bool is_a_solution( string partial,int n,int k) { 
    if(partial.length() == n*2 )  
     return true;
    return false;
      }
    string constructCandidate(int n,string input,string partial, int k) { 
    int xcount=0,ycount=0;
    int count;
    int i;
    string candi;
    if(k == 0)  
        return string("(");
    else { 
        for(i=0;i

提交回复
热议问题