From 02b0b99f79bb8f308c96af783681a8482d0bb81a Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 8 Feb 2025 08:21:22 +0800 Subject: [PATCH 1/4] feat: add solutions to lc problem: No.0063 No.0063.Unique Paths II --- .../0000-0099/0063.Unique Paths II/README.md | 114 ++++++++++++++-- .../0063.Unique Paths II/README_EN.md | 122 +++++++++++++++--- .../0063.Unique Paths II/Solution.cpp | 7 +- .../0063.Unique Paths II/Solution.js | 22 ++++ .../0063.Unique Paths II/Solution.rs | 26 ++++ .../0063.Unique Paths II/Solution2.js | 30 +++++ .../images/robot_maze.png | Bin 9489 -> 0 bytes 7 files changed, 291 insertions(+), 30 deletions(-) create mode 100644 solution/0000-0099/0063.Unique Paths II/Solution.js create mode 100644 solution/0000-0099/0063.Unique Paths II/Solution.rs create mode 100644 solution/0000-0099/0063.Unique Paths II/Solution2.js delete mode 100644 solution/0000-0099/0063.Unique Paths II/images/robot_maze.png diff --git a/solution/0000-0099/0063.Unique Paths II/README.md b/solution/0000-0099/0063.Unique Paths II/README.md index f770bea10abac..24244cc8cbbfa 100644 --- a/solution/0000-0099/0063.Unique Paths II/README.md +++ b/solution/0000-0099/0063.Unique Paths II/README.md @@ -65,13 +65,13 @@ tags: ### 方法一:记忆化搜索 -我们设计一个函数 $dfs(i, j)$ 表示从网格 $(i, j)$ 到网格 $(m - 1, n - 1)$ 的路径数。其中 $m$ 和 $n$ 分别是网格的行数和列数。 +我们设计一个函数 $\textit{dfs}(i, j)$ 表示从网格 $(i, j)$ 到网格 $(m - 1, n - 1)$ 的路径数。其中 $m$ 和 $n$ 分别是网格的行数和列数。 -函数 $dfs(i, j)$ 的执行过程如下: +函数 $\textit{dfs}(i, j)$ 的执行过程如下: -- 如果 $i \ge m$ 或者 $j \ge n$,或者 $obstacleGrid[i][j] = 1$,则路径数为 $0$; +- 如果 $i \ge m$ 或者 $j \ge n$,或者 $\textit{obstacleGrid}[i][j] = 1$,则路径数为 $0$; - 如果 $i = m - 1$ 且 $j = n - 1$,则路径数为 $1$; -- 否则,路径数为 $dfs(i + 1, j) + dfs(i, j + 1)$。 +- 否则,路径数为 $\textit{dfs}(i + 1, j) + \textit{dfs}(i, j + 1)$。 为了避免重复计算,我们可以使用记忆化搜索的方法。 @@ -135,9 +135,8 @@ class Solution { public: int uniquePathsWithObstacles(vector>& obstacleGrid) { int m = obstacleGrid.size(), n = obstacleGrid[0].size(); - int f[m][n]; - memset(f, -1, sizeof(f)); - function dfs = [&](int i, int j) { + vector> f(m, vector(n, -1)); + auto dfs = [&](this auto&& dfs, int i, int j) { if (i >= m || j >= n || obstacleGrid[i][j]) { return 0; } @@ -206,6 +205,64 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn unique_paths_with_obstacles(obstacle_grid: Vec>) -> i32 { + let m = obstacle_grid.len(); + let n = obstacle_grid[0].len(); + let mut f = vec![vec![-1; n]; m]; + Self::dfs(0, 0, &obstacle_grid, &mut f) + } + + fn dfs(i: usize, j: usize, obstacle_grid: &Vec>, f: &mut Vec>) -> i32 { + let m = obstacle_grid.len(); + let n = obstacle_grid[0].len(); + if i >= m || j >= n || obstacle_grid[i][j] == 1 { + return 0; + } + if i == m - 1 && j == n - 1 { + return 1; + } + if f[i][j] != -1 { + return f[i][j]; + } + let down = Self::dfs(i + 1, j, obstacle_grid, f); + let right = Self::dfs(i, j + 1, obstacle_grid, f); + f[i][j] = down + right; + f[i][j] + } +} +``` + +#### JavaScript + +```js +/** + * @param {number[][]} obstacleGrid + * @return {number} + */ +var uniquePathsWithObstacles = function (obstacleGrid) { + const m = obstacleGrid.length; + const n = obstacleGrid[0].length; + const f = Array.from({ length: m }, () => Array(n).fill(-1)); + const dfs = (i, j) => { + if (i >= m || j >= n || obstacleGrid[i][j] === 1) { + return 0; + } + if (i === m - 1 && j === n - 1) { + return 1; + } + if (f[i][j] === -1) { + f[i][j] = dfs(i + 1, j) + dfs(i, j + 1); + } + return f[i][j]; + }; + return dfs(0, 0); +}; +``` + @@ -214,12 +271,12 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { ### 方法二:动态规划 -我们定义 $f[i][j]$ 表示到达网格 $(i,j)$ 的路径数。 +我们可以使用动态规划的方法,定义一个二维数组 $f$,其中 $f[i][j]$ 表示从网格 $(0,0)$ 到网格 $(i,j)$ 的路径数。 -首先初始化 $f$ 第一列和第一行的所有值,然后遍历其它行和列,有两种情况: +我们首先初始化 $f$ 的第一列和第一行的所有值,然后遍历其它行和列,有两种情况: -- 若 $obstacleGrid[i][j] = 1$,说明路径数为 $0$,那么 $f[i][j] = 0$; -- 若 $obstacleGrid[i][j] = 0$,则 $f[i][j] = f[i - 1][j] + f[i][j - 1]$。 +- 若 $\textit{obstacleGrid}[i][j] = 1$,说明路径数为 $0$,那么 $f[i][j] = 0$; +- 若 $\textit{obstacleGrid}[i][j] = 0$,则 $f[i][j] = f[i - 1][j] + f[i][j - 1]$。 最后返回 $f[m - 1][n - 1]$ 即可。 @@ -413,6 +470,41 @@ impl Solution { } ``` +#### JavaScript + +```js +/** + * @param {number[][]} obstacleGrid + * @return {number} + */ +var uniquePathsWithObstacles = function (obstacleGrid) { + const m = obstacleGrid.length; + const n = obstacleGrid[0].length; + const f = Array.from({ length: m }, () => Array(n).fill(0)); + for (let i = 0; i < m; i++) { + if (obstacleGrid[i][0] === 1) { + break; + } + f[i][0] = 1; + } + for (let i = 0; i < n; i++) { + if (obstacleGrid[0][i] === 1) { + break; + } + f[0][i] = 1; + } + for (let i = 1; i < m; i++) { + for (let j = 1; j < n; j++) { + if (obstacleGrid[i][j] === 1) { + continue; + } + f[i][j] = f[i - 1][j] + f[i][j - 1]; + } + } + return f[m - 1][n - 1]; +}; +``` + diff --git a/solution/0000-0099/0063.Unique Paths II/README_EN.md b/solution/0000-0099/0063.Unique Paths II/README_EN.md index 9ea8e7ff71466..0ad42812f6587 100644 --- a/solution/0000-0099/0063.Unique Paths II/README_EN.md +++ b/solution/0000-0099/0063.Unique Paths II/README_EN.md @@ -63,17 +63,17 @@ There are two ways to reach the bottom-right corner: ### Solution 1: Memoization Search -We design a function $dfs(i, j)$ to represent the number of paths from the grid $(i, j)$ to the grid $(m - 1, n - 1)$, where $m$ and $n$ are the number of rows and columns of the grid, respectively. +We design a function $\textit{dfs}(i, j)$ to represent the number of paths from the grid $(i, j)$ to the grid $(m - 1, n - 1)$. Here, $m$ and $n$ are the number of rows and columns of the grid, respectively. -The execution process of the function $dfs(i, j)$ is as follows: +The execution process of the function $\textit{dfs}(i, j)$ is as follows: -- If $i \ge m$ or $j \ge n$, or $obstacleGrid[i][j] = 1$, then the number of paths is $0$; -- If $i = m - 1$ and $j = n - 1$, then the number of paths is $1$; -- Otherwise, the number of paths is $dfs(i + 1, j) + dfs(i, j + 1)$. +- If $i \ge m$ or $j \ge n$, or $\textit{obstacleGrid}[i][j] = 1$, the number of paths is $0$; +- If $i = m - 1$ and $j = n - 1$, the number of paths is $1$; +- Otherwise, the number of paths is $\textit{dfs}(i + 1, j) + \textit{dfs}(i, j + 1)$. -To avoid repeated calculations, we can use the method of memoization search. +To avoid redundant calculations, we can use memoization. -The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$. Where $m$ and $n$ are the number of rows and columns of the grid, respectively. +The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$. Here, $m$ and $n$ are the number of rows and columns of the grid, respectively. @@ -133,9 +133,8 @@ class Solution { public: int uniquePathsWithObstacles(vector>& obstacleGrid) { int m = obstacleGrid.size(), n = obstacleGrid[0].size(); - int f[m][n]; - memset(f, -1, sizeof(f)); - function dfs = [&](int i, int j) { + vector> f(m, vector(n, -1)); + auto dfs = [&](this auto&& dfs, int i, int j) { if (i >= m || j >= n || obstacleGrid[i][j]) { return 0; } @@ -204,6 +203,64 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn unique_paths_with_obstacles(obstacle_grid: Vec>) -> i32 { + let m = obstacle_grid.len(); + let n = obstacle_grid[0].len(); + let mut f = vec![vec![-1; n]; m]; + Self::dfs(0, 0, &obstacle_grid, &mut f) + } + + fn dfs(i: usize, j: usize, obstacle_grid: &Vec>, f: &mut Vec>) -> i32 { + let m = obstacle_grid.len(); + let n = obstacle_grid[0].len(); + if i >= m || j >= n || obstacle_grid[i][j] == 1 { + return 0; + } + if i == m - 1 && j == n - 1 { + return 1; + } + if f[i][j] != -1 { + return f[i][j]; + } + let down = Self::dfs(i + 1, j, obstacle_grid, f); + let right = Self::dfs(i, j + 1, obstacle_grid, f); + f[i][j] = down + right; + f[i][j] + } +} +``` + +#### JavaScript + +```js +/** + * @param {number[][]} obstacleGrid + * @return {number} + */ +var uniquePathsWithObstacles = function (obstacleGrid) { + const m = obstacleGrid.length; + const n = obstacleGrid[0].length; + const f = Array.from({ length: m }, () => Array(n).fill(-1)); + const dfs = (i, j) => { + if (i >= m || j >= n || obstacleGrid[i][j] === 1) { + return 0; + } + if (i === m - 1 && j === n - 1) { + return 1; + } + if (f[i][j] === -1) { + f[i][j] = dfs(i + 1, j) + dfs(i, j + 1); + } + return f[i][j]; + }; + return dfs(0, 0); +}; +``` + @@ -212,16 +269,16 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { ### Solution 2: Dynamic Programming -We define $f[i][j]$ as the number of paths to reach the grid $(i,j)$. +We can use a dynamic programming approach by defining a 2D array $f$, where $f[i][j]$ represents the number of paths from the grid $(0,0)$ to the grid $(i,j)$. -First, initialize all values in the first column and first row of $f$. Then, traverse other rows and columns, there are two cases: +We first initialize all values in the first column and the first row of $f$, then traverse the other rows and columns with two cases: -- If $obstacleGrid[i][j] = 1$, it means the number of paths is $0$, so $f[i][j] = 0$; -- If $obstacleGrid[i][j] = 0$, then $f[i][j] = f[i - 1][j] + f[i][j - 1]$. +- If $\textit{obstacleGrid}[i][j] = 1$, it means the number of paths is $0$, so $f[i][j] = 0$; +- If $\textit{obstacleGrid}[i][j] = 0$, then $f[i][j] = f[i - 1][j] + f[i][j - 1]$. Finally, return $f[m - 1][n - 1]$. -The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$. Where $m$ and $n$ are the number of rows and columns of the grid, respectively. +The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$. Here, $m$ and $n$ are the number of rows and columns of the grid, respectively. @@ -388,6 +445,41 @@ impl Solution { } ``` +#### JavaScript + +```js +/** + * @param {number[][]} obstacleGrid + * @return {number} + */ +var uniquePathsWithObstacles = function (obstacleGrid) { + const m = obstacleGrid.length; + const n = obstacleGrid[0].length; + const f = Array.from({ length: m }, () => Array(n).fill(0)); + for (let i = 0; i < m; i++) { + if (obstacleGrid[i][0] === 1) { + break; + } + f[i][0] = 1; + } + for (let i = 0; i < n; i++) { + if (obstacleGrid[0][i] === 1) { + break; + } + f[0][i] = 1; + } + for (let i = 1; i < m; i++) { + for (let j = 1; j < n; j++) { + if (obstacleGrid[i][j] === 1) { + continue; + } + f[i][j] = f[i - 1][j] + f[i][j - 1]; + } + } + return f[m - 1][n - 1]; +}; +``` + diff --git a/solution/0000-0099/0063.Unique Paths II/Solution.cpp b/solution/0000-0099/0063.Unique Paths II/Solution.cpp index b363c7f95535d..44a8ae85688df 100644 --- a/solution/0000-0099/0063.Unique Paths II/Solution.cpp +++ b/solution/0000-0099/0063.Unique Paths II/Solution.cpp @@ -2,9 +2,8 @@ class Solution { public: int uniquePathsWithObstacles(vector>& obstacleGrid) { int m = obstacleGrid.size(), n = obstacleGrid[0].size(); - int f[m][n]; - memset(f, -1, sizeof(f)); - function dfs = [&](int i, int j) { + vector> f(m, vector(n, -1)); + auto dfs = [&](this auto&& dfs, int i, int j) { if (i >= m || j >= n || obstacleGrid[i][j]) { return 0; } @@ -18,4 +17,4 @@ class Solution { }; return dfs(0, 0); } -}; \ No newline at end of file +}; diff --git a/solution/0000-0099/0063.Unique Paths II/Solution.js b/solution/0000-0099/0063.Unique Paths II/Solution.js new file mode 100644 index 0000000000000..ee92b5eb809c5 --- /dev/null +++ b/solution/0000-0099/0063.Unique Paths II/Solution.js @@ -0,0 +1,22 @@ +/** + * @param {number[][]} obstacleGrid + * @return {number} + */ +var uniquePathsWithObstacles = function (obstacleGrid) { + const m = obstacleGrid.length; + const n = obstacleGrid[0].length; + const f = Array.from({ length: m }, () => Array(n).fill(-1)); + const dfs = (i, j) => { + if (i >= m || j >= n || obstacleGrid[i][j] === 1) { + return 0; + } + if (i === m - 1 && j === n - 1) { + return 1; + } + if (f[i][j] === -1) { + f[i][j] = dfs(i + 1, j) + dfs(i, j + 1); + } + return f[i][j]; + }; + return dfs(0, 0); +}; diff --git a/solution/0000-0099/0063.Unique Paths II/Solution.rs b/solution/0000-0099/0063.Unique Paths II/Solution.rs new file mode 100644 index 0000000000000..770d83e0f78e9 --- /dev/null +++ b/solution/0000-0099/0063.Unique Paths II/Solution.rs @@ -0,0 +1,26 @@ +impl Solution { + pub fn unique_paths_with_obstacles(obstacle_grid: Vec>) -> i32 { + let m = obstacle_grid.len(); + let n = obstacle_grid[0].len(); + let mut f = vec![vec![-1; n]; m]; + Self::dfs(0, 0, &obstacle_grid, &mut f) + } + + fn dfs(i: usize, j: usize, obstacle_grid: &Vec>, f: &mut Vec>) -> i32 { + let m = obstacle_grid.len(); + let n = obstacle_grid[0].len(); + if i >= m || j >= n || obstacle_grid[i][j] == 1 { + return 0; + } + if i == m - 1 && j == n - 1 { + return 1; + } + if f[i][j] != -1 { + return f[i][j]; + } + let down = Self::dfs(i + 1, j, obstacle_grid, f); + let right = Self::dfs(i, j + 1, obstacle_grid, f); + f[i][j] = down + right; + f[i][j] + } +} diff --git a/solution/0000-0099/0063.Unique Paths II/Solution2.js b/solution/0000-0099/0063.Unique Paths II/Solution2.js new file mode 100644 index 0000000000000..818efb306de28 --- /dev/null +++ b/solution/0000-0099/0063.Unique Paths II/Solution2.js @@ -0,0 +1,30 @@ +/** + * @param {number[][]} obstacleGrid + * @return {number} + */ +var uniquePathsWithObstacles = function (obstacleGrid) { + const m = obstacleGrid.length; + const n = obstacleGrid[0].length; + const f = Array.from({ length: m }, () => Array(n).fill(0)); + for (let i = 0; i < m; i++) { + if (obstacleGrid[i][0] === 1) { + break; + } + f[i][0] = 1; + } + for (let i = 0; i < n; i++) { + if (obstacleGrid[0][i] === 1) { + break; + } + f[0][i] = 1; + } + for (let i = 1; i < m; i++) { + for (let j = 1; j < n; j++) { + if (obstacleGrid[i][j] === 1) { + continue; + } + f[i][j] = f[i - 1][j] + f[i][j - 1]; + } + } + return f[m - 1][n - 1]; +}; diff --git a/solution/0000-0099/0063.Unique Paths II/images/robot_maze.png b/solution/0000-0099/0063.Unique Paths II/images/robot_maze.png deleted file mode 100644 index e1aa28362c8cf96dea0af15107a48ab534a0d3fb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9489 zcmb_?by!>7vu^OH(qQ5*oMh{e4(#Xx>%Fqc(R1OU8V0s#KO0KhHsC;uG)z>O0C*fRkDgnj@3 zlA;hVoHE?a{T2_Q&9R-1u#(>G7G=8IfO4IF4p=U~kx0WPwa z=<@@YCm}8zj*>GPjDrRF_>n%5nJYE`eUe)eaY*`jLN%Z|8DA|jq#_K9xPPOZ* zp(iYvDyB~2D1B&~vC%5Yrg{|&J!tQT>t>@+ZYycfUefziu!y9id=#&E#q;em6y!WP zt7`0O?A`(K$+&g-7`sOAR|r}by|ntXP0js~tg#*(my<_xk-@y!7c`78VEqDNjWSgBGBAg_#wk_q0HMI%*0B964GGh}Xm(4ChylCK!dJHXi(^2BG z*DJ=CuFs%oChS-)g29&l`gf1KvQcw(;X8pP?;RcAqyE4f0GKNzwKH;t)`OpO9gU)N zil$2ry$1^VN=kr#OdK98zdC!Bn=tfJz+-zG?(40!B)!c-$KM(${BnS;c>0=_&u=8- z_v9Bt%3?!~@0ga5pN@tZ z5#tS*@yC>W2AKZBR`_?1TzUFuOVJASoy&K*&9ei;jiFRQAZHp>mT9UDTB1LP0DvJD zV6oga-G)kmg-aG4Fbp?R=A=f&-_IUzY32W@vlQil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5&j+?;Hj0&HA-8k_<` uyaGa8JS?1?LY$l=1NXrHOTf;-!rIdFe-?lwNmU~S0CLhwQZNaV!2bdsV^H`2 From fc27033559dabcd4eed612b7aba34120cc4f0936 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 8 Feb 2025 08:26:41 +0800 Subject: [PATCH 2/4] fix: remove --- .../0000-0099/0063.Unique Paths II/README.md | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/solution/0000-0099/0063.Unique Paths II/README.md b/solution/0000-0099/0063.Unique Paths II/README.md index 24244cc8cbbfa..4b10cca3b87e0 100644 --- a/solution/0000-0099/0063.Unique Paths II/README.md +++ b/solution/0000-0099/0063.Unique Paths II/README.md @@ -414,29 +414,6 @@ function uniquePathsWithObstacles(obstacleGrid: number[][]): number { } ``` -#### TypeScript - -```ts -function uniquePathsWithObstacles(obstacleGrid: number[][]): number { - const m = obstacleGrid.length; - const n = obstacleGrid[0].length; - const f: number[][] = Array.from({ length: m }, () => Array(n).fill(-1)); - const dfs = (i: number, j: number): number => { - if (i >= m || j >= n || obstacleGrid[i][j] === 1) { - return 0; - } - if (i === m - 1 && j === n - 1) { - return 1; - } - if (f[i][j] === -1) { - f[i][j] = dfs(i + 1, j) + dfs(i, j + 1); - } - return f[i][j]; - }; - return dfs(0, 0); -} -``` - #### Rust ```rust From 4679323eb06f036febf7f65ea81c9a788b9ebaf3 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 8 Feb 2025 08:42:12 +0800 Subject: [PATCH 3/4] fix: site --- README_EN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_EN.md b/README_EN.md index d81be5f48286a..60ab3a4d4505f 100644 --- a/README_EN.md +++ b/README_EN.md @@ -20,7 +20,7 @@ This project contains solutions for problems from LeetCode, "Coding Interviews ( ## Sites -https://doocs.github.io/leetcode +https://doocs.github.io/leetcode/en ## Solutions From 1bc72e5f48a53be5325cf0e1d9338c8f977cb313 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 8 Feb 2025 08:45:53 +0800 Subject: [PATCH 4/4] fix: site --- README_EN.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README_EN.md b/README_EN.md index 60ab3a4d4505f..47ba7fdfb46b0 100644 --- a/README_EN.md +++ b/README_EN.md @@ -18,7 +18,7 @@ This project contains solutions for problems from LeetCode, "Coding Interviews ( [中文文档](/README.md) -## Sites +## Site https://doocs.github.io/leetcode/en @@ -31,8 +31,8 @@ https://doocs.github.io/leetcode/en ## JavaScript & Database Practice -- [JavaScript Practice](/solution/JAVASCRIPT_README_EN.md) -- [Database Practice](/solution/DATABASE_README_EN.md) +- [JavaScript](/solution/JAVASCRIPT_README_EN.md) +- [Database](/solution/DATABASE_README_EN.md) ## Topics