diff --git a/0088-merge-sorted-array/0088-merge-sorted-array.js b/0088-merge-sorted-array/0088-merge-sorted-array.js index 25fd86f..6c3ebc1 100644 --- a/0088-merge-sorted-array/0088-merge-sorted-array.js +++ b/0088-merge-sorted-array/0088-merge-sorted-array.js @@ -6,12 +6,19 @@ * @return {void} Do not return anything, modify nums1 in-place instead. */ var merge = function (nums1, m, nums2, n) { - let i = 0 - while (i <= nums2.length - 1) { - nums1[m] = nums2[i] - m++ - i++ + let l = 0 + for (let i = nums1.length - 1; i >= 0; i--) { + if (nums2[l] == undefined) { + break + } + if (nums1[i] == 0) { + nums1[i] = nums2[l] + l++ + } + else { + break + } } - return nums1.sort((a, b) => a - b) - -}; \ No newline at end of file + nums1 = nums1.sort((a, b) => a - b) + return nums1.length +};