From d5353e1735d2d80a28a7a653d97dade4bf7c66e3 Mon Sep 17 00:00:00 2001 From: markwang Date: Tue, 6 Aug 2024 11:07:14 +0800 Subject: [PATCH] =?UTF-8?q?62.=E4=B8=8D=E5=90=8C=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0Go=E6=95=B0=E8=AE=BA=E6=96=B9=E6=B3=95?= 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 b451704b..5b46caa9 100644 --- a/problems/0062.不同路径.md +++ b/problems/0062.不同路径.md @@ -371,6 +371,7 @@ class Solution: ``` ### Go +动态规划 ```Go func uniquePaths(m int, n int) int { dp := make([][]int, m) @@ -390,6 +391,26 @@ func uniquePaths(m int, n int) int { } ``` +数论方法 +```Go +func uniquePaths(m int, n int) int { + numerator := 1 + denominator := m - 1 + count := m - 1 + t := m + n - 2 + for count > 0 { + numerator *= t + t-- + for denominator != 0 && numerator % denominator == 0 { + numerator /= denominator + denominator-- + } + count-- + } + return numerator +} +``` + ### Javascript ```Javascript