From 001a7a8b2dfeb875065234960c6307ae0bb67cca Mon Sep 17 00:00:00 2001 From: ChrisLin Date: Tue, 8 Jun 2021 23:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00062.=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E8=B7=AF=E5=BE=84Javascript=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0062.不同路径.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/problems/0062.不同路径.md b/problems/0062.不同路径.md index 60b65818..47cb41af 100644 --- a/problems/0062.不同路径.md +++ b/problems/0062.不同路径.md @@ -308,6 +308,27 @@ func uniquePaths(m int, n int) int { } ``` +Javascript: +```Javascript +var uniquePaths = function(m, n) { + const dp = Array(m).fill().map(item => Array(n)) + + for (let i = 0; i < m; ++i) { + dp[i][0] = 1 + } + + for (let i = 0; i < n; ++i) { + dp[0][i] = 1 + } + + for (let i = 1; i < m; ++i) { + for (let j = 1; j < n; ++j) { + dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + } + } + return dp[m - 1][n - 1] +}; +``` -----------------------