Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7994f89

Browse files
add q62
1 parent 522f0c7 commit 7994f89

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

‎.idea/workspace.xml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787

8888
* [q5_最长回文子串](/src/动态规划/q5_最长回文子串)
8989
* [q53_最大子序和](/src/动态规划/q53_最大子序和)
90+
* [q62_不同路径](/src/动态规划/q62_不同路径)
9091
* [q64_最小路径和](/src/动态规划/q64_最小路径和)
9192
* [q70_爬楼梯](/src/动态规划/q70_爬楼梯)
9293
* [q118_杨辉三角](/src/动态规划/q118_杨辉三角)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package 动态规划.q62_不同路径;
2+
3+
/**
4+
* 动态规划 dp[i][j]是到达i, j的最多路径 dp[i][j] = dp[i-1][j] + dp[i][j-1] o(m*n)
5+
*/
6+
public class Solution {
7+
8+
public int uniquePaths(int m, int n) {
9+
if (m < 1 || n < 1) {
10+
return 0;
11+
}
12+
int[][] dp = new int[m][n];
13+
for (int i = 0; i < n; i++) {
14+
dp[0][i] = 1;
15+
}
16+
for (int i = 0; i < m; i++) {
17+
dp[i][0] = 1;
18+
}
19+
for (int i = 1; i < m; i++) {
20+
for (int j = 1; j < n; j++) {
21+
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
22+
}
23+
}
24+
return dp[m - 1][n - 1];
25+
}
26+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /