Skip to content

Commit 8dc8180

Browse files
committed
feat: add cs solutions to lc problem: No.0064. Minimum Path Sum
1 parent 84b8195 commit 8dc8180

File tree

18 files changed

+115
-19
lines changed

18 files changed

+115
-19
lines changed

solution/0000-0099/0064.Minimum Path Sum/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ func min(a, b int) int {
149149
}
150150
```
151151

152+
### **C#**
153+
154+
```cs
155+
public class Solution {
156+
public int MinPathSum(int[][] grid) {
157+
int m = grid.Length, n = grid[0].Length;
158+
int[,] dp = new int[m, n];
159+
dp[0, 0] = grid[0][0];
160+
for (int i = 1; i < m; ++i)
161+
{
162+
dp[i, 0] = dp[i - 1, 0] + grid[i][0];
163+
}
164+
for (int j = 1; j < n; ++j)
165+
{
166+
dp[0, j] = dp[0, j - 1] + grid[0][j];
167+
}
168+
for (int i = 1; i < m; ++i)
169+
{
170+
for (int j = 1; j < n; ++j)
171+
{
172+
dp[i, j] = Math.Min(dp[i - 1, j], dp[i, j - 1]) + grid[i][j];
173+
}
174+
}
175+
return dp[m- 1, n - 1];
176+
}
177+
}
178+
```
179+
152180
### **...**
153181

154182
```

solution/0000-0099/0064.Minimum Path Sum/README_EN.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,34 @@ func min(a, b int) int {
137137
}
138138
```
139139

140+
### **C#**
141+
142+
```cs
143+
public class Solution {
144+
public int MinPathSum(int[][] grid) {
145+
int m = grid.Length, n = grid[0].Length;
146+
int[,] dp = new int[m, n];
147+
dp[0, 0] = grid[0][0];
148+
for (int i = 1; i < m; ++i)
149+
{
150+
dp[i, 0] = dp[i - 1, 0] + grid[i][0];
151+
}
152+
for (int j = 1; j < n; ++j)
153+
{
154+
dp[0, j] = dp[0, j - 1] + grid[0][j];
155+
}
156+
for (int i = 1; i < m; ++i)
157+
{
158+
for (int j = 1; j < n; ++j)
159+
{
160+
dp[i, j] = Math.Min(dp[i - 1, j], dp[i, j - 1]) + grid[i][j];
161+
}
162+
}
163+
return dp[m- 1, n - 1];
164+
}
165+
}
166+
```
167+
140168
### **...**
141169

142170
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Solution {
2+
public int MinPathSum(int[][] grid) {
3+
int m = grid.Length, n = grid[0].Length;
4+
int[,] dp = new int[m, n];
5+
dp[0, 0] = grid[0][0];
6+
for (int i = 1; i < m; ++i)
7+
{
8+
dp[i, 0] = dp[i - 1, 0] + grid[i][0];
9+
}
10+
for (int j = 1; j < n; ++j)
11+
{
12+
dp[0, j] = dp[0, j - 1] + grid[0][j];
13+
}
14+
for (int i = 1; i < m; ++i)
15+
{
16+
for (int j = 1; j < n; ++j)
17+
{
18+
dp[i, j] = Math.Min(dp[i - 1, j], dp[i, j - 1]) + grid[i][j];
19+
}
20+
}
21+
return dp[m- 1, n - 1];
22+
}
23+
}

solution/0000-0099/0099.Recover Binary Search Tree/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Solution:
5858
first = None
5959
second = None
6060
prev = None
61+
6162
def recoverTree(self, root: TreeNode) -> None:
6263
"""
6364
Do not return anything, modify root in-place instead.

solution/0000-0099/0099.Recover Binary Search Tree/README_EN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Solution:
5151
first = None
5252
second = None
5353
prev = None
54+
5455
def recoverTree(self, root: TreeNode) -> None:
5556
"""
5657
Do not return anything, modify root in-place instead.

solution/0000-0099/0099.Recover Binary Search Tree/Solution.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Solution:
88
first = None
99
second = None
1010
prev = None
11+
1112
def recoverTree(self, root: TreeNode) -> None:
1213
"""
1314
Do not return anything, modify root in-place instead.

solution/0500-0599/0589.N-ary Tree Preorder Traversal/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ class Node:
6868
self.children = children
6969
"""
7070

71+
7172
class Solution:
7273
def preorder(self, root: 'Node') -> List[int]:
7374
if not root:
7475
return []
76+
7577
def PO(root):
7678
res.append(root.val)
7779
for i in root.children:
7880
PO(i)
79-
res=[]
81+
res = []
8082
PO(root)
8183
return res
8284
```

solution/0500-0599/0589.N-ary Tree Preorder Traversal/README_EN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ class Node:
5555
self.children = children
5656
"""
5757

58+
5859
class Solution:
5960
def preorder(self, root: 'Node') -> List[int]:
6061
if not root:
6162
return []
63+
6264
def PO(root):
6365
res.append(root.val)
6466
for i in root.children:
6567
PO(i)
66-
res=[]
68+
res = []
6769
PO(root)
6870
return res
6971
```

solution/0500-0599/0589.N-ary Tree Preorder Traversal/Solution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ def __init__(self, val=None, children=None):
66
self.children = children
77
"""
88

9+
910
class Solution:
1011
def preorder(self, root: 'Node') -> List[int]:
1112
if not root:
1213
return []
14+
1315
def PO(root):
1416
res.append(root.val)
1517
for i in root.children:
1618
PO(i)
17-
res=[]
19+
res = []
1820
PO(root)
1921
return res

solution/0500-0599/0590.N-ary Tree Postorder Traversal/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,21 @@ class Node:
6868
self.val = val
6969
self.children = children
7070
"""
71+
72+
7173
class Solution:
7274
def postorder(self, root: 'Node') -> List[int]:
7375
if not root:
7476
return []
77+
7578
def PO(root):
76-
if root==None:
79+
if root == None:
7780
return res
7881
else:
7982
for i in root.children:
8083
PO(i)
8184
res.append(i.val)
82-
res=[]
85+
res = []
8386
PO(root)
8487
res.append(root.val)
8588
return res

0 commit comments

Comments
 (0)