From 615730e9b920ab1bbf03a5e0c46b4e4e039210ad Mon Sep 17 00:00:00 2001 From: linlihong <747682928@qq.com> Date: Thu, 26 Sep 2024 17:24:39 +0800 Subject: [PATCH] =?UTF-8?q?2024/9/26=20Hot100=20=E5=A4=9A=E7=BB=B4dp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cool/hot100/multi_dp/Num62.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/cool/hot100/multi_dp/Num62.java diff --git a/src/main/java/com/cool/hot100/multi_dp/Num62.java b/src/main/java/com/cool/hot100/multi_dp/Num62.java new file mode 100644 index 0000000..dac049f --- /dev/null +++ b/src/main/java/com/cool/hot100/multi_dp/Num62.java @@ -0,0 +1,33 @@ +package com.cool.hot100.multi_dp; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/26/17:16 + * DayNumber 4 + * Hard 2 + * Level ? + * @Description 62. 不同路径 + * @Link https://leetcode.cn/problems/unique-paths/description/?envType=study-plan-v2&envId=top-100-liked + */ +public class Num62 { + + + public int uniquePaths(int m, int n) { + int[][] dp = new int[m][n]; + for (int i = 0; i < n; i++) { + dp[0][i] = 1; + } + for (int i = 0; i < m; i++) { + dp[i][0] = 1; + } + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; + } + } + return dp[m - 1][n - 1]; + } + +}