Skip to content

Commit 2a52a20

Browse files
committed
update readme
1 parent 3096940 commit 2a52a20

File tree

5 files changed

+18
-118
lines changed

5 files changed

+18
-118
lines changed

0088-merge-sorted-array/0088-merge-sorted-array.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0088-merge-sorted-array/README.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

Python/0088-merge-sorted-array.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55

66
class Solution:
77
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
8-
p1 = m - 1
9-
p2 = n - 1
10-
for p in range(m + n - 1, -1, -1):
11-
if p2 < 0:
12-
break
13-
if p1 >= 0 and nums1[p1] > nums2[p2]:
14-
nums1[p] = nums1[p1]
15-
p1 -= 1
16-
else:
17-
nums1[p] = nums2[p2]
18-
p2 -= 1
8+
idx1 = m - 1
9+
idx2 = n - 1
10+
currIdx = m + n - 1
1911

20-
return nums1
12+
while idx2 >= 0:
13+
if idx1 >= 0 and nums1[idx1] > nums2[idx2]:
14+
nums1[currIdx] = nums1[idx1]
15+
idx1 -= 1
16+
else:
17+
nums1[currIdx] = nums2[idx2]
18+
idx2 -= 1
19+
currIdx -= 1
2120

2221

2322
nums1 = [1, 2, 3, 0, 0, 0]

README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,3 @@ It helps others discover the repo and keeps the project growing.
115115
---
116116

117117
Feedback / Questions → open an Issue or reach out on [LinkedIn](https://www.linkedin.com/in/hogan-l/)
118-
119-
<!---LeetCode Topics Start-->
120-
# LeetCode Topics
121-
## Array
122-
| |
123-
| ------- |
124-
| [0088-merge-sorted-array](https://github.com/hogan-tech/leetcode-solution/tree/master/0088-merge-sorted-array) |
125-
## Two Pointers
126-
| |
127-
| ------- |
128-
| [0088-merge-sorted-array](https://github.com/hogan-tech/leetcode-solution/tree/master/0088-merge-sorted-array) |
129-
## Sorting
130-
| |
131-
| ------- |
132-
| [0088-merge-sorted-array](https://github.com/hogan-tech/leetcode-solution/tree/master/0088-merge-sorted-array) |
133-
<!---LeetCode Topics End-->

Readme/0088-merge-sorted-array.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<h2> 16022 2155
2-
88. Merge Sorted Array</h2><hr><div><p>You are given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in <strong>non-decreasing order</strong>, and two integers <code>m</code> and <code>n</code>, representing the number of elements in <code>nums1</code> and <code>nums2</code> respectively.</p>
1+
<h2><a href="https://leetcode.com/problems/merge-sorted-array">88. Merge Sorted Array</a></h2><h3>Easy</h3><hr><p>You are given two integer arrays <code>nums1</code> and <code>nums2</code>, sorted in <strong>non-decreasing order</strong>, and two integers <code>m</code> and <code>n</code>, representing the number of elements in <code>nums1</code> and <code>nums2</code> respectively.</p>
32

43
<p><strong>Merge</strong> <code>nums1</code> and <code>nums2</code> into a single array sorted in <strong>non-decreasing order</strong>.</p>
54

@@ -8,23 +7,26 @@
87
<p>&nbsp;</p>
98
<p><strong class="example">Example 1:</strong></p>
109

11-
<pre><strong>Input:</strong> nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
10+
<pre>
11+
<strong>Input:</strong> nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
1212
<strong>Output:</strong> [1,2,2,3,5,6]
1313
<strong>Explanation:</strong> The arrays we are merging are [1,2,3] and [2,5,6].
1414
The result of the merge is [<u>1</u>,<u>2</u>,2,<u>3</u>,5,6] with the underlined elements coming from nums1.
1515
</pre>
1616

1717
<p><strong class="example">Example 2:</strong></p>
1818

19-
<pre><strong>Input:</strong> nums1 = [1], m = 1, nums2 = [], n = 0
19+
<pre>
20+
<strong>Input:</strong> nums1 = [1], m = 1, nums2 = [], n = 0
2021
<strong>Output:</strong> [1]
2122
<strong>Explanation:</strong> The arrays we are merging are [1] and [].
2223
The result of the merge is [1].
2324
</pre>
2425

2526
<p><strong class="example">Example 3:</strong></p>
2627

27-
<pre><strong>Input:</strong> nums1 = [0], m = 0, nums2 = [1], n = 1
28+
<pre>
29+
<strong>Input:</strong> nums1 = [0], m = 0, nums2 = [1], n = 1
2830
<strong>Output:</strong> [1]
2931
<strong>Explanation:</strong> The arrays we are merging are [] and [1].
3032
The result of the merge is [1].
@@ -44,4 +46,3 @@ Note that because m = 0, there are no elements in nums1. The 0 is only there to
4446

4547
<p>&nbsp;</p>
4648
<p><strong>Follow up: </strong>Can you come up with an algorithm that runs in <code>O(m + n)</code> time?</p>
47-
</div>

0 commit comments

Comments
 (0)