//这题感觉不如前两题回溯清楚,还要再看看
class Solution { public: vector<string> generateParenthesis(int n) { vector<string> res; string add; DFS(res,add,n,n); return res; } void DFS(vector<string>& res,string add,int x,int y){ if(x > y) return; if(x == 0&&y == 0){ res.push_back(add); } else{ if(x > 0)DFS(res,add+"(",x-1,y); if(y > 0)DFS(res,add+")",x,y-1); } } };