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 2c2ada1 commit 4244009Copy full SHA for 4244009
algorithms/easy/merge/merge.js
@@ -0,0 +1,25 @@
1
+// description: https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/8/sorting-and-searching/52/
2
+// 合并两个有序数组
3
+
4
+/**
5
+ * @param {number[]} nums1
6
+ * @param {number} m
7
+ * @param {number[]} nums2
8
+ * @param {number} n
9
+ * @return {void} Do not return anything, modify nums1 in-place instead.
10
+ */
11
+var merge = function(nums1, m, nums2, n) {
12
+ var i = m - 1;
13
+ var j = n - 1;
14
+ var k = m + n - 1;
15
+ while (i >= 0 && j >= 0) {
16
+ if (nums1[i] > nums2[j]) {
17
+ nums1[k--] = nums1[i--];
18
+ } else {
19
+ nums1[k--] = nums2[j--];
20
+ }
21
22
+ while (j >= 0) {
23
24
25
+};
0 commit comments