Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leetcode 62. 不同路径 #动态规划 #34

Open
webVueBlog opened this issue May 29, 2022 · 1 comment
Open

leetcode 62. 不同路径 #动态规划 #34

webVueBlog opened this issue May 29, 2022 · 1 comment

Comments

@webVueBlog
Copy link
Member

image
62. 不同路径

@webVueBlog
Copy link
Member Author

62. 不同路径

/*
 * @lc app=leetcode.cn id=62 lang=javascript
 *
 * [62] 不同路径
 */

// @lc code=start
/**
 * @param {number} m
 * @param {number} n
 * @return {number}

(56 ms)
 */
var uniquePaths = function(m, n) {
 let dp = new Array(m).fill(0).map(v => new Array(n).fill(0));
 dp[0][0] = 1;
 for(let i = 0; i < m; i++) {
  for(let j = 0; j < n; j++) {
   // 起始
   if(i === 0 && j === 0) continue;
   // 不越界
   let top = i <= 0 ? 0 : dp[i-1][j];
   let left = j <= 0 ? 0 : dp[i][j-1];
   dp[i][j] = top + left;
  }
 }
 return dp[m-1][n-1]
};
// @lc code=end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant