Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions solution/0000-0099/0022.Generate Parentheses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,37 @@ impl Solution {
}
```

```rust
impl Solution {
pub fn generate_parenthesis(n: i32) -> Vec<String> {
let mut dp: Vec<Vec<String>> = vec![vec![]; n as usize + 1];

// Initialize the dp vector
dp[0].push(String::from(""));
dp[1].push(String::from("()"));

// Begin the actual dp process
for i in 2..=n as usize {
for j in 0..i as usize {
let dp_c = dp.clone();
let first_half = &dp_c[j];
let second_half = &dp_c[i - j - 1];

for f in first_half {
for s in second_half {
let f_c = f.clone();
let cur_str = f_c + "(" + &*s + ")";
dp[i].push(cur_str);
}
}
}
}

dp[n as usize].clone()
}
}
```

### **...**

```
Expand Down
31 changes: 31 additions & 0 deletions solution/0000-0099/0022.Generate Parentheses/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,37 @@ impl Solution {
}
```

```rust
impl Solution {
pub fn generate_parenthesis(n: i32) -> Vec<String> {
let mut dp: Vec<Vec<String>> = vec![vec![]; n as usize + 1];

// Initialize the dp vector
dp[0].push(String::from(""));
dp[1].push(String::from("()"));

// Begin the actual dp process
for i in 2..=n as usize {
for j in 0..i as usize {
let dp_c = dp.clone();
let first_half = &dp_c[j];
let second_half = &dp_c[i - j - 1];

for f in first_half {
for s in second_half {
let f_c = f.clone();
let cur_str = f_c + "(" + &*s + ")";
dp[i].push(cur_str);
}
}
}
}

dp[n as usize].clone()
}
}
```

### **...**

```
Expand Down