class Solution { public: vector<string> answer; void dfs(int l,int r,string s){ if(l==0&&r==0){ answer.emplace_back(s); return; } if(l>0){ s+='('; dfs(l-1,r,s); s.pop_back(); } if(r>0&&l<r){ s+=')'; dfs(l,r-1,s); s.pop_back(); } } vector<string> generateParenthesis(int n) { string s; dfs(n,n,s); return answer; } };