[nb] Commit
This commit is contained in:
		
							
								
								
									
										56
									
								
								dynamic-programming/22-generate-parenthesis/golang/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								dynamic-programming/22-generate-parenthesis/golang/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| package main | ||||
| /* | ||||
| Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. | ||||
| Example 1: | ||||
|  | ||||
| Input: n = 3 | ||||
| Output: ["((()))","(()())","(())()","()(())","()()()"] | ||||
| Example 2: | ||||
|   ()()(); (())();  ((()));  | ||||
|   ()(()); | ||||
|   (()()) | ||||
|  | ||||
| Input: n = 1 | ||||
| Output: ["()"] | ||||
|   | ||||
|   ()(); (()) | ||||
|  | ||||
| Constraints: | ||||
|  | ||||
| 1 <= n <= 8 | ||||
| */ | ||||
|  | ||||
| func rec(int index, dp map[string]string) { | ||||
| } | ||||
|  | ||||
|  | ||||
| func generateParenthesis(n int)[] string { | ||||
|  | ||||
|   if n == 1 { | ||||
|     return []string{"()"} | ||||
|   } | ||||
|  | ||||
|   if n == 2 { | ||||
|     return []string{"()()", "(())"} | ||||
|   } | ||||
|  | ||||
|   var output = make([]string, 0)  | ||||
|   var dp = map[string]string{} | ||||
|   var start_string string = "" | ||||
|   for i := 0; i < n - 1; i++ { | ||||
|     start_string = start_string + "()" | ||||
|     out_arr = a | ||||
|   } | ||||
|   output = append(output, start_string) | ||||
|  | ||||
|  | ||||
|   for i := 1; i < n - 1; i++ { | ||||
|     result := rec(i+1, dp) + rec(i-1)  | ||||
|   } | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
| func main() { | ||||
|  | ||||
| } | ||||
							
								
								
									
										17
									
								
								dynamic-programming/22-generate-parenthesis/js/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								dynamic-programming/22-generate-parenthesis/js/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| function generateParenthesis(n) { | ||||
|   if (n == 1) { | ||||
|     return ['()']; | ||||
|   } | ||||
|  | ||||
|   if (n == 2) { | ||||
|     return ['()()', '(())']; | ||||
|   } | ||||
|  | ||||
|   const input = []; | ||||
|   for (i = 0; i < n; i++) { | ||||
|     input.push('()'); | ||||
|   } | ||||
|  | ||||
|   for(i = 0; i < n; i++; i++) { | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user