Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fbd11e4

Browse files
feat: update solutions (doocs#2258)
1 parent 47f059e commit fbd11e4

File tree

6 files changed

+28
-46
lines changed

6 files changed

+28
-46
lines changed

‎solution/0000-0099/0088.Merge Sorted Array/README.md‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void {
131131
}
132132
```
133133

134+
```ts
135+
/**
136+
Do not return anything, modify nums1 in-place instead.
137+
*/
138+
function merge(nums1: number[], m: number, nums2: number[], n: number): void {
139+
nums1.length = m;
140+
nums2.length = n;
141+
nums1.push(...nums2);
142+
nums1.sort((a, b) => a - b);
143+
}
144+
```
145+
134146
```rust
135147
impl Solution {
136148
pub fn merge(nums1: &mut Vec<i32>, m: i32, nums2: &mut Vec<i32>, n: i32) {
@@ -198,22 +210,4 @@ class Solution {
198210

199211
<!-- tabs:end -->
200212

201-
### 方法二
202-
203-
<!-- tabs:start -->
204-
205-
```ts
206-
/**
207-
Do not return anything, modify nums1 in-place instead.
208-
*/
209-
function merge(nums1: number[], m: number, nums2: number[], n: number): void {
210-
nums1.length = m;
211-
nums2.length = n;
212-
nums1.push(...nums2);
213-
nums1.sort((a, b) => a - b);
214-
}
215-
```
216-
217-
<!-- tabs:end -->
218-
219213
<!-- end -->

‎solution/0000-0099/0088.Merge Sorted Array/README_EN.md‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ function merge(nums1: number[], m: number, nums2: number[], n: number): void {
126126
}
127127
```
128128

129+
```ts
130+
/**
131+
Do not return anything, modify nums1 in-place instead.
132+
*/
133+
function merge(nums1: number[], m: number, nums2: number[], n: number): void {
134+
nums1.length = m;
135+
nums2.length = n;
136+
nums1.push(...nums2);
137+
nums1.sort((a, b) => a - b);
138+
}
139+
```
140+
129141
```rust
130142
impl Solution {
131143
pub fn merge(nums1: &mut Vec<i32>, m: i32, nums2: &mut Vec<i32>, n: i32) {
@@ -193,22 +205,4 @@ class Solution {
193205

194206
<!-- tabs:end -->
195207

196-
### Solution 2
197-
198-
<!-- tabs:start -->
199-
200-
```ts
201-
/**
202-
Do not return anything, modify nums1 in-place instead.
203-
*/
204-
function merge(nums1: number[], m: number, nums2: number[], n: number): void {
205-
nums1.length = m;
206-
nums2.length = n;
207-
nums1.push(...nums2);
208-
nums1.sort((a, b) => a - b);
209-
}
210-
```
211-
212-
<!-- tabs:end -->
213-
214208
<!-- end -->

‎solution/0000-0099/0091.Decode Ways/README.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@
7575

7676
时间复杂度 $O(n),ドル空间复杂度 $O(n)$。其中 $n$ 是字符串的长度。
7777

78-
我们注意到,状态 $f[i]$ 仅与状态 $f[i-1]$ 和状态 $f[i-2]$ 有关,而与其他状态无关,因此我们可以使用两个变量代替这两个状态,使得原来的空间复杂度 $O(n)$ 降低至 $O(1)$。
79-
8078
<!-- tabs:start -->
8179

8280
```python
@@ -187,7 +185,7 @@ public class Solution {
187185

188186
<!-- tabs:end -->
189187

190-
### 方法二
188+
我们注意到,状态 $f[i]$ 仅与状态 $f[i-1]$ 和状态 $f[i-2]$ 有关,而与其他状态无关,因此我们可以使用两个变量代替这两个状态,使得原来的空间复杂度 $O(n)$ 降低至 $O(1)$。
191189

192190
<!-- tabs:start -->
193191

‎solution/0000-0099/0091.Decode Ways/README_EN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public class Solution {
182182

183183
<!-- tabs:end -->
184184

185-
### Solution 2
185+
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)$.
186186

187187
<!-- tabs:start -->
188188

‎solution/0000-0099/0097.Interleaving String/README.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ $$
357357

358358
时间复杂度 $O(m \times n),ドル空间复杂度 $O(m \times n)$。其中 $m$ 和 $n$ 分别是字符串 $s_1$ 和 $s_2$ 的长度。
359359

360-
我们注意到,状态 $f[i][j]$ 只和状态 $f[i - 1][j]$、$f[i][j - 1]$、$f[i - 1][j - 1]$ 有关,因此我们可以使用滚动数组优化空间复杂度,将空间复杂度优化到 $O(n)$。
361-
362360
<!-- tabs:start -->
363361

364362
```python
@@ -508,7 +506,7 @@ public class Solution {
508506

509507
<!-- tabs:end -->
510508

511-
### 方法三
509+
我们注意到,状态 $f[i][j]$ 只和状态 $f[i - 1][j]$、$f[i][j - 1]$、$f[i - 1][j - 1]$ 有关,因此我们可以使用滚动数组优化空间复杂度,将空间复杂度优化到 $O(n)$。
512510

513511
<!-- tabs:start -->
514512

‎solution/0000-0099/0097.Interleaving String/README_EN.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ The answer is $f[m][n]$.
357357

358358
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.
359359

360-
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)$.
361-
362360
<!-- tabs:start -->
363361

364362
```python
@@ -508,7 +506,7 @@ public class Solution {
508506

509507
<!-- tabs:end -->
510508

511-
### Solution 3
509+
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)$.
512510

513511
<!-- tabs:start -->
514512

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /