Skip to content

Commit c5c3890

Browse files
committed
update 64
1 parent 1350953 commit c5c3890

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ python problem.py https://www.lintcode.com/problem/92 -l cpp
4040
| [] | [9c-dp.md](./list/9c-dp.md) | 42/45 | 3 vips |
4141
| [] | [geekbang.md](./list/geekbang.md) | 55/55 | - |
4242
| [] | [leetcode101.md](./list/leetcode101.md) | 183/184 | 1 vip |
43-
| [🔲] | [9c-advanced.md](./list/9c-advanced.md) | 46/94 | 9 vips |
43+
| [🔲] | [9c-advanced.md](./list/9c-advanced.md) | 49/94 | 10 vips |
4444
| [🔲] | [leetcode-contest.md](./list/leetcode-contest.md) | 10/40 | - |
4545

4646
**Solved**: 438 problems

leetcode/64.minimum-path-sum.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@
3232
class Solution {
3333
public:
3434
int minPathSum(vector<vector<int>>& grid) {
35-
int m = grid.size();
36-
int n = grid[0].size();
37-
vector<vector<int>> dp(m, vector<int>(n, 0));
35+
int n = grid.size();
36+
int m = grid[0].size();
37+
vector<vector<int>> dp(n, vector<int>(m, 0));
3838

39-
for (int i = 0; i < m; i++) {
40-
for (int j = 0; j < n; j++) {
39+
for (int i = 0; i < n; i++) {
40+
for (int j = 0; j < m; j++) {
4141
if (i == 0 && j == 0) {
42-
dp[0][0] = grid[0][0];
42+
dp[0][0] = grid[i][j];
4343
} else if (i == 0) {
44-
dp[0][j] = dp[0][j - 1] + grid[0][j];
44+
dp[0][j] = dp[i][j - 1] + grid[i][j];
4545
} else if (j == 0) {
46-
dp[i][0] = dp[i - 1][0] + grid[i][0];
46+
dp[i][0] = dp[i - 1][j] + grid[i][j];
4747
} else {
4848
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + grid[i][j];
4949
}
5050
}
5151
}
52-
return dp[m - 1][n - 1];
52+
return dp[n - 1][m - 1];
5353
}
5454
};

leetcode/64.minimum-path-sum.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131

3232
class Solution:
3333
def minPathSum(self, grid: List[List[int]]) -> int:
34-
m = len(grid)
35-
n = len(grid[0])
36-
dp = [[0 for j in range(n)] for i in range(m)]
34+
n = len(grid)
35+
m = len(grid[0])
3736

38-
for i in range(m):
39-
for j in range(n):
37+
dp = [[0] * m for i in range(n)]
38+
for i in range(n):
39+
for j in range(m):
4040
if i == 0 and j == 0:
41-
dp[0][0] = grid[0][0]
41+
dp[i][j] = grid[i][j]
4242
elif i == 0:
43-
dp[0][j] = dp[0][j - 1] + grid[0][j]
43+
dp[i][j] = dp[i][j - 1] + grid[i][j]
4444
elif j == 0:
45-
dp[i][0] = dp[i - 1][0] + grid[i][0]
45+
dp[i][j] = dp[i - 1][j] + grid[i][j]
4646
else:
4747
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + grid[i][j]
4848

49-
return dp[m - 1][n - 1]
49+
return dp[n - 1][m - 1]

lintcode/631.maximal-square-ii.vip

Whitespace-only changes.

list/9c-advanced.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@
7070
54. https://leetcode.com/problems/house-robber-ii/
7171
55. https://leetcode.com/problems/climbing-stairs/
7272
56. https://www.lintcode.com/problem/fibonacci/
73+
57. https://leetcode.com/problems/maximal-square/
74+
58. https://www.lintcode.com/problem/maximal-square-ii/
75+
59. https://leetcode.com/problems/unique-paths/
76+
60. https://leetcode.com/problems/minimum-path-sum/
7377

74-
- https://www.lintcode.com/problem/maximal-square/
75-
- https://www.lintcode.com/problem/maximal-square-ii/
76-
- https://www.lintcode.com/problem/unique-paths/
77-
- https://www.lintcode.com/problem/minimum-path-sum/
7878
- https://www.lintcode.com/problem/edit-distance/
7979
- https://www.lintcode.com/problem/longest-continuous-increasing-subsequence/
8080
- https://www.lintcode.com/problem/longest-continuous-increasing-subsequence-ii/

0 commit comments

Comments
 (0)