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

+28
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

+28
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
```
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

+1
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

+1
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

+1
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

+3-1
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

+3-1
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

+3-1
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

+5-2
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

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,20 @@ class Node:
5151
self.children = children
5252
"""
5353

54+
5455
class Solution:
5556
def postorder(self, root: 'Node') -> List[int]:
5657
if not root:
5758
return []
59+
5860
def PO(root):
59-
if root==None:
61+
if root == None:
6062
return res
6163
else:
6264
for i in root.children:
6365
PO(i)
6466
res.append(i.val)
65-
res=[]
67+
res = []
6668
PO(root)
6769
res.append(root.val)
6870
return res

solution/0500-0599/0590.N-ary Tree Postorder Traversal/Solution.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ def __init__(self, val=None, children=None):
66
self.children = children
77
"""
88

9+
910
class Solution:
1011
def postorder(self, root: 'Node') -> List[int]:
1112
if not root:
1213
return []
14+
1315
def PO(root):
14-
if root==None:
16+
if root == None:
1517
return res
1618
else:
1719
for i in root.children:
1820
PO(i)
1921
res.append(i.val)
20-
res=[]
22+
res = []
2123
PO(root)
2224
res.append(root.val)
2325
return res

solution/0900-0999/0997.Find the Town Judge/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ class Solution:
8585
values.add(i[0])
8686
if i[1] in dic:
8787
dic[i[1]].append(i[0])
88-
else: dic[i[1]] = [i[0]]
88+
else:
89+
dic[i[1]] = [i[0]]
8990

9091
for key, value in dic.items():
9192
if len(dic[key]) == n-1 and key not in values:
92-
return key
93-
return -1
93+
return k
9494
```
9595

9696
### **Java**

solution/0900-0999/0997.Find the Town Judge/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ class Solution:
9494
values.add(i[0])
9595
if i[1] in dic:
9696
dic[i[1]].append(i[0])
97-
else: dic[i[1]] = [i[0]]
97+
else:
98+
dic[i[1]] = [i[0]]
9899

99100
for key, value in dic.items():
100101
if len(dic[key]) == n-1 and key not in values:
101-
return key
102-
return -1
102+
return k
103103
```
104104

105105
### **Java**

solution/0900-0999/0997.Find the Town Judge/Solution.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def findJudge(self, n: int, trust: List[List[int]]) -> int:
88
values.add(i[0])
99
if i[1] in dic:
1010
dic[i[1]].append(i[0])
11-
else: dic[i[1]] = [i[0]]
11+
else:
12+
dic[i[1]] = [i[0]]
1213

1314
for key, value in dic.items():
1415
if len(dic[key]) == n-1 and key not in values:

solution/1700-1799/1791.Find Center of Star Graph/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
```python
5555
class Solution:
5656
def findCenter(self, edges: List[List[int]]) -> int:
57-
return edges[0][0] if edges[0][0]==edges[1][0] or edges[0][0]==edges[1][1] else edges[0][1]
57+
return edges[0][0] if edges[0][0] == edges[1][0] or edges[0][0] == edges[1][1] else edges[0][1]
5858
```
5959

6060
### **Java**

solution/1700-1799/1791.Find Center of Star Graph/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
```python
6969
class Solution:
7070
def findCenter(self, edges: List[List[int]]) -> int:
71-
return edges[0][0] if edges[0][0]==edges[1][0] or edges[0][0]==edges[1][1] else edges[0][1]
71+
return edges[0][0] if edges[0][0] == edges[1][0] or edges[0][0] == edges[1][1] else edges[0][1]
7272
```
7373

7474
### **Java**
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Solution:
22
def findCenter(self, edges: List[List[int]]) -> int:
3-
return edges[0][0] if edges[0][0]==edges[1][0] or edges[0][0]==edges[1][1] else edges[0][1]
3+
return edges[0][0] if edges[0][0] == edges[1][0] or edges[0][0] == edges[1][1] else edges[0][1]

0 commit comments

Comments
 (0)