From 9a570843c4a01ce62e4ea35dacd0ee20fde51165 Mon Sep 17 00:00:00 2001 From: carry <2641257231@qq.com> Date: Sun, 23 Mar 2025 14:44:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=A7=84=E5=88=92=E9=A2=98:=E7=89=9B=E5=AE=A2=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E8=B7=AF=E5=BE=84=E7=9A=84=E6=95=B0=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniquePaths.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 uniquePaths.cpp diff --git a/uniquePaths.cpp b/uniquePaths.cpp new file mode 100644 index 0000000..038609b --- /dev/null +++ b/uniquePaths.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +using namespace std; + +class Solution { +public: + int uniquePaths(int m, int n) { + if((m == 1)||(n == 1)){ + return 1; + } + else{ + vector> dp(m, std::vector(n,0)); + for(int i = 0;i < m;i++){ + dp[i][0] = 1; + } + for(int i = 0;i < n;i++){ + dp[0][i] = 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]; + } + } +}; + +int main(){ + Solution mysolution; + cout << mysolution.uniquePaths(2,1); + return 0; +}