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
27 changes: 27 additions & 0 deletions solution/0000-0099/0022.Generate Parentheses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,33 @@ var generateParenthesis = function (n) {
};
```

#### C#

```cs
public class Solution {
private List<string> ans = new List<string>();
private int n;

public List<string> GenerateParenthesis(int n) {
this.n = n;
Dfs(0, 0, "");
return ans;
}

private void Dfs(int l, int r, string t) {
if (l > n || r > n || l < r) {
return;
}
if (l == n && r == n) {
ans.Add(t);
return;
}
Dfs(l + 1, r, t + "(");
Dfs(l, r + 1, t + ")");
}
}
```

#### PHP

```php
Expand Down
27 changes: 27 additions & 0 deletions solution/0000-0099/0022.Generate Parentheses/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,33 @@ var generateParenthesis = function (n) {
};
```

#### C#

```cs
public class Solution {
private List<string> ans = new List<string>();
private int n;

public List<string> GenerateParenthesis(int n) {
this.n = n;
Dfs(0, 0, "");
return ans;
}

private void Dfs(int l, int r, string t) {
if (l > n || r > n || l < r) {
return;
}
if (l == n && r == n) {
ans.Add(t);
return;
}
Dfs(l + 1, r, t + "(");
Dfs(l, r + 1, t + ")");
}
}
```

#### PHP

```php
Expand Down
22 changes: 22 additions & 0 deletions solution/0000-0099/0022.Generate Parentheses/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Solution {
private List<string> ans = new List<string>();
private int n;

public List<string> GenerateParenthesis(int n) {
this.n = n;
Dfs(0, 0, "");
return ans;
}

private void Dfs(int l, int r, string t) {
if (l > n || r > n || l < r) {
return;
}
if (l == n && r == n) {
ans.Add(t);
return;
}
Dfs(l + 1, r, t + "(");
Dfs(l, r + 1, t + ")");
}
}