We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e1e0af4 commit c392978Copy full SHA for c392978
python_solutions/0088_merge_sorted_array.py
@@ -0,0 +1,23 @@
1
+def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
2
+ """
3
+ Do not return anything, modify nums1 in-place instead.
4
5
+ # Iterate through both of the given arrays simultaneously
6
+ while (m > 0 and n > 0):
7
+ curr1 = nums1[m - 1]
8
+ curr2 = nums2[n - 1]
9
+
10
+ if(curr1 >= curr2):
11
+ nums1[(m + n) - 1] = curr1
12
+ m -= 1
13
+ else:
14
+ nums1[(m + n) - 1] = curr2
15
+ n -= 1
16
+ # If there are smaller elements left in nums2, copy them over
17
+ # No need to do this for leftover nums1 elements, since we are
18
+ # merging into nums1 and the elements will already be there
19
+ while (n > 0):
20
+ nums1[n - 1] = nums2[n - 1]
21
22
23
+ return nums1
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments