diff --git a/solution/0000-0099/0088.Merge Sorted Array/README.md b/solution/0000-0099/0088.Merge Sorted Array/README.md index c3c09dc90630f..fae3770570388 100644 --- a/solution/0000-0099/0088.Merge Sorted Array/README.md +++ b/solution/0000-0099/0088.Merge Sorted Array/README.md @@ -131,6 +131,18 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void { } ``` +```ts +/** + Do not return anything, modify nums1 in-place instead. + */ +function merge(nums1: number[], m: number, nums2: number[], n: number): void { + nums1.length = m; + nums2.length = n; + nums1.push(...nums2); + nums1.sort((a, b) => a - b); +} +``` + ```rust impl Solution { pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) { @@ -198,22 +210,4 @@ class Solution { -### 方法二 - - - -```ts -/** - Do not return anything, modify nums1 in-place instead. - */ -function merge(nums1: number[], m: number, nums2: number[], n: number): void { - nums1.length = m; - nums2.length = n; - nums1.push(...nums2); - nums1.sort((a, b) => a - b); -} -``` - - - diff --git a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md index e15af0f9dc54f..d184e5d107467 100644 --- a/solution/0000-0099/0088.Merge Sorted Array/README_EN.md +++ b/solution/0000-0099/0088.Merge Sorted Array/README_EN.md @@ -126,6 +126,18 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void { } ``` +```ts +/** + Do not return anything, modify nums1 in-place instead. + */ +function merge(nums1: number[], m: number, nums2: number[], n: number): void { + nums1.length = m; + nums2.length = n; + nums1.push(...nums2); + nums1.sort((a, b) => a - b); +} +``` + ```rust impl Solution { pub fn merge(nums1: &mut Vec, m: i32, nums2: &mut Vec, n: i32) { @@ -193,22 +205,4 @@ class Solution { -### Solution 2 - - - -```ts -/** - Do not return anything, modify nums1 in-place instead. - */ -function merge(nums1: number[], m: number, nums2: number[], n: number): void { - nums1.length = m; - nums2.length = n; - nums1.push(...nums2); - nums1.sort((a, b) => a - b); -} -``` - - - diff --git a/solution/0000-0099/0091.Decode Ways/README.md b/solution/0000-0099/0091.Decode Ways/README.md index d0844d54928f3..8fbd5df2d9d6f 100644 --- a/solution/0000-0099/0091.Decode Ways/README.md +++ b/solution/0000-0099/0091.Decode Ways/README.md @@ -75,8 +75,6 @@ 时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 是字符串的长度。 -我们注意到,状态 $f[i]$ 仅与状态 $f[i-1]$ 和状态 $f[i-2]$ 有关,而与其他状态无关,因此我们可以使用两个变量代替这两个状态,使得原来的空间复杂度 $O(n)$ 降低至 $O(1)$。 - ```python @@ -187,7 +185,7 @@ public class Solution { -### 方法二 +我们注意到,状态 $f[i]$ 仅与状态 $f[i-1]$ 和状态 $f[i-2]$ 有关,而与其他状态无关,因此我们可以使用两个变量代替这两个状态,使得原来的空间复杂度 $O(n)$ 降低至 $O(1)$。 diff --git a/solution/0000-0099/0091.Decode Ways/README_EN.md b/solution/0000-0099/0091.Decode Ways/README_EN.md index 0d8ab6ac5f993..ac173f7eaaa0d 100644 --- a/solution/0000-0099/0091.Decode Ways/README_EN.md +++ b/solution/0000-0099/0091.Decode Ways/README_EN.md @@ -182,7 +182,7 @@ public class Solution { -### Solution 2 +We notice that the state $f[i]$ is only related to the states $f[i-1]$ and $f[i-2]$, and is irrelevant to other states. Therefore, we can use two variables to replace these two states, reducing the original space complexity from $O(n)$ to $O(1)$. diff --git a/solution/0000-0099/0097.Interleaving String/README.md b/solution/0000-0099/0097.Interleaving String/README.md index b2402f3d6afa3..db02138a7bce0 100644 --- a/solution/0000-0099/0097.Interleaving String/README.md +++ b/solution/0000-0099/0097.Interleaving String/README.md @@ -357,8 +357,6 @@ $$ 时间复杂度 $O(m \times n)$,空间复杂度 $O(m \times n)$。其中 $m$ 和 $n$ 分别是字符串 $s_1$ 和 $s_2$ 的长度。 -我们注意到,状态 $f[i][j]$ 只和状态 $f[i - 1][j]$、$f[i][j - 1]$、$f[i - 1][j - 1]$ 有关,因此我们可以使用滚动数组优化空间复杂度,将空间复杂度优化到 $O(n)$。 - ```python @@ -508,7 +506,7 @@ public class Solution { -### 方法三 +我们注意到,状态 $f[i][j]$ 只和状态 $f[i - 1][j]$、$f[i][j - 1]$、$f[i - 1][j - 1]$ 有关,因此我们可以使用滚动数组优化空间复杂度,将空间复杂度优化到 $O(n)$。 diff --git a/solution/0000-0099/0097.Interleaving String/README_EN.md b/solution/0000-0099/0097.Interleaving String/README_EN.md index 62ba9ed5da645..587b7c430cf57 100644 --- a/solution/0000-0099/0097.Interleaving String/README_EN.md +++ b/solution/0000-0099/0097.Interleaving String/README_EN.md @@ -357,8 +357,6 @@ The answer is $f[m][n]$. The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$. Here, $m$ and $n$ are the lengths of strings $s_1$ and $s_2$ respectively. -We notice that the state $f[i][j]$ is only related to the states $f[i - 1][j]$, $f[i][j - 1]$, and $f[i - 1][j - 1]$. Therefore, we can use a rolling array to optimize the space complexity, reducing the original space complexity from $O(m \times n)$ to $O(n)$. - ```python @@ -508,7 +506,7 @@ public class Solution { -### Solution 3 +We notice that the state $f[i][j]$ is only related to the states $f[i - 1][j]$, $f[i][j - 1]$, and $f[i - 1][j - 1]$. Therefore, we can use a rolling array to optimize the space complexity, reducing the original space complexity from $O(m \times n)$ to $O(n)$.