Answers for "find all balanced braces"

C++
0

find all balanced braces

void  find_balanced_braces(size_t const &n, size_t open, size_t close, size_t index, string &s, vector<string> &res){
    if(open == n and close == n)
        res.push_back(s);
    else{
        if(open < n){
            s[index] = '(';
            find_balanced_braces(n, open+1, close, index+1, s, res);
        }
        if(close < open){
            s[index] = ')';
            find_balanced_braces(n, open, close+1, index+1, s, res);
        }
    }
}

find_balanced_braces(n, 0, 0, 0, s, res);
Posted by: Guest on August-05-2021

Code answers related to "find all balanced braces"

Browse Popular Code Answers by Language