feat: 2025-10-31打卡
This commit is contained in:
31
62.unique-paths.java
Normal file
31
62.unique-paths.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @lc app=leetcode id=62 lang=java
|
||||
*
|
||||
* [62] Unique Paths
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public int uniquePaths(int m, int n) {
|
||||
int[][] dp = new int[m][n];
|
||||
for(int i = 0; i<dp.length; i++) {
|
||||
for(int j=0; j<dp[0].length; j++) {
|
||||
dp[i][j] = 0;
|
||||
}
|
||||
}
|
||||
dp[0][0] = 1;
|
||||
for(int i = 0; i<dp.length; i++) {
|
||||
for(int j=0; j<dp[0].length; j++) {
|
||||
if(i-1>=0) {
|
||||
dp[i][j] += dp[i-1][j];
|
||||
}
|
||||
if(j-1 >=0) {
|
||||
dp[i][j] += dp[i][j-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[m-1][n-1];
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user