Created
April 16, 2024 15:47
-
-
Save yevmoroz/dab6479b70a09dfc8e7e3702434d6f69 to your computer and use it in GitHub Desktop.
leetcode unique paths mxn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} m | |
* @param {number} n | |
* @return {number} | |
*/ | |
function uniquePaths(m, n) { | |
let arr = []; | |
for (let i = 0; i <=m; i++) { | |
arr.push(new Array(n + 1).fill(0)); | |
} | |
arr[1][0] = 1; | |
for (let i = 1; i <=m; i++){ | |
for(let j = 1; j<=n; j++){ | |
arr[i][j] = arr[i - 1][j]+arr[i][j - 1]; | |
} | |
} | |
return arr[m][n]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment