mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	Rename *22.cpp to 22.cpp
This commit is contained in:
		
							
								
								
									
										23
									
								
								dynamic planning/22.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								dynamic planning/22.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Solution {
 | 
			
		||||
    public:
 | 
			
		||||
        vector<string> generateParenthesis(int n) {
 | 
			
		||||
            vector<string> v;
 | 
			
		||||
            dfs(v, "", n, n);
 | 
			
		||||
            return v;
 | 
			
		||||
        }
 | 
			
		||||
        void dfs(vector<string> &v, string s, int lc, int rc){
 | 
			
		||||
            if(lc == 0 && rc == 0){
 | 
			
		||||
                v.push_back(s);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if(lc != 0) dfs(v, s + '(', lc - 1, rc);
 | 
			
		||||
            if(rc != 0 && rc - 1 >= lc){
 | 
			
		||||
                dfs(v, s + ')', lc, rc - 1);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
		Reference in New Issue
	
	Block a user