Description
Submission
class Solution { public: vector<string> generateParenthesis(int n) { vector<string> res; generateParenthesisUtil(n, n, "", res); return res; } private: void generateParenthesisUtil(int left, int right, string str, vector<string>& res) { if(left == 0 && right == 0) res.push_back(str); if(left > 0) generateParenthesisUtil(left - 1, right, str + "(", res); if(right > 0 && left < right) generateParenthesisUtil(left, right - 1, str + ")", res); } };