*22.cpp 570 B

1234567891011121314151617181920212223
  1. #include <string>
  2. #include <vector>
  3. using namespace std;
  4. class Solution {
  5. public:
  6. vector<string> generateParenthesis(int n) {
  7. vector<string> v;
  8. dfs(v, "", n, n);
  9. return v;
  10. }
  11. void dfs(vector<string> &v, string s, int lc, int rc){
  12. if(lc == 0 && rc == 0){
  13. v.push_back(s);
  14. return;
  15. }
  16. if(lc != 0) dfs(v, s + '(', lc - 1, rc);
  17. if(rc != 0 && rc - 1 >= lc){
  18. dfs(v, s + ')', lc, rc - 1);
  19. }
  20. }
  21. };
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。