Skip to content

Commit b91b246

Browse files
committed
Create README - LeetHub
1 parent faccee8 commit b91b246

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

88-merge-sorted-array/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<h2><a href="https://leetcode.com/problems/merge-sorted-array/">88. Merge Sorted Array</a></h2><h3>Easy</h3><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>
2+
3+
<p><strong>Merge</strong> <code>nums1</code> and <code>nums2</code> into a single array sorted in <strong>non-decreasing order</strong>.</p>
4+
5+
<p>The final sorted array should not be returned by the function, but instead be <em>stored inside the array </em><code>nums1</code>. To accommodate this, <code>nums1</code> has a length of <code>m + n</code>, where the first <code>m</code> elements denote the elements that should be merged, and the last <code>n</code> elements are set to <code>0</code> and should be ignored. <code>nums2</code> has a length of <code>n</code>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong>Example 1:</strong></p>
9+
10+
<pre><strong>Input:</strong> nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
11+
<strong>Output:</strong> [1,2,2,3,5,6]
12+
<strong>Explanation:</strong> The arrays we are merging are [1,2,3] and [2,5,6].
13+
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.
14+
</pre>
15+
16+
<p><strong>Example 2:</strong></p>
17+
18+
<pre><strong>Input:</strong> nums1 = [1], m = 1, nums2 = [], n = 0
19+
<strong>Output:</strong> [1]
20+
<strong>Explanation:</strong> The arrays we are merging are [1] and [].
21+
The result of the merge is [1].
22+
</pre>
23+
24+
<p><strong>Example 3:</strong></p>
25+
26+
<pre><strong>Input:</strong> nums1 = [0], m = 0, nums2 = [1], n = 1
27+
<strong>Output:</strong> [1]
28+
<strong>Explanation:</strong> The arrays we are merging are [] and [1].
29+
The result of the merge is [1].
30+
Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>nums1.length == m + n</code></li>
38+
<li><code>nums2.length == n</code></li>
39+
<li><code>0 &lt;= m, n &lt;= 200</code></li>
40+
<li><code>1 &lt;= m + n &lt;= 200</code></li>
41+
<li><code>-10<sup>9</sup> &lt;= nums1[i], nums2[j] &lt;= 10<sup>9</sup></code></li>
42+
</ul>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Follow up: </strong>Can you come up with an algorithm that runs in <code>O(m + n)</code> time?</p>
46+
</div>

0 commit comments

Comments
 (0)