Skip to content

Commit eb5ab75

Browse files
authored
Update 088._merge_sorted_array.md
1 parent 4a4efbe commit eb5ab75

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

docs/Leetcode_Solutions/088._merge_sorted_array.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
1-
### 88. Merge Sorted Array
1+
# 88. Merge Sorted Array
22

3+
**<font color=red>难度: Easy</font>**
34

4-
题目:
5-
<https://leetcode.com/problems/merge-sorted-array/>
5+
## 刷题内容
66

7+
> 原题连接
78
8-
难度 : Easy
9+
* https://leetcode.com/problems/merge-sorted-array/description/
910

10-
### 思路:
11+
> 内容描述
12+
13+
```
14+
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
15+
16+
Note:
17+
18+
The number of elements initialized in nums1 and nums2 are m and n respectively.
19+
You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.
20+
Example:
21+
22+
Input:
23+
nums1 = [1,2,3,0,0,0], m = 3
24+
nums2 = [2,5,6], n = 3
25+
26+
Output: [1,2,2,3,5,6]
27+
```
28+
29+
## 解题方案
30+
31+
> 思路 1
1132
1233
给的数组可能是这样的
1334

@@ -17,7 +38,7 @@
1738
- n : 1
1839

1940

20-
所以要判断m和n是不是仍然大于0
41+
所以要判断m和n是不是仍然大于0, 但是m不需要了,因为我们本来就是要在nums1的基础上改,m如果还大于0的话我们不需要改nums1了,保留不变即可
2142

2243

2344
AC代码
@@ -42,5 +63,5 @@ class Solution:
4263
n -= 1
4364
if n > 0:
4465
nums1[:n] = nums2[:n]
45-
4666
```
67+

0 commit comments

Comments
 (0)