Skip to content

Commit 3a2e0c9

Browse files
author
baochau.dinh
committed
js-concepts: leetcode prob.88 - merge sorted array
1 parent a07a75d commit 3a2e0c9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var merge = function(nums1, m, nums2, n) {
2+
let first = 0, second = 0;
3+
let tmp = [];
4+
while (first < m || second < n) {
5+
if (nums1[first] <= nums2[second]) {
6+
tmp.push(nums1[first]);
7+
first++;
8+
} else {
9+
tmp.push(nums2[second]);
10+
second++;
11+
}
12+
}
13+
while (first < m) {
14+
tmp.push(nums1[first]);
15+
first++;
16+
}
17+
while (second < n) {
18+
tmp.push(nums2[second]);
19+
second++;
20+
}
21+
22+
return tmp;
23+
};
24+
25+
console.log(merge([]))

0 commit comments

Comments
 (0)