leetcode 88. 合并两个有序数组
/** * @param {number[]} nums1 * @param {number} m * @param {number[]} nums2 * @param {number} n * @return {void} Do not return anything, modify nums1 in-place instead. */ var merge = function(nums1, m, nums2, n) { let newArr = [] let l = 0; let r = 0; while(l<m&&r<n){ if(nums1[l]<=nums2[r]){ newArr.push(nums1[l]); l++; }else{ newArr.push(nums2[r]); r++; } } while(l<m){ newArr.push(nums1[l]); l++; } while(r<n){ newArr.push(nums2[r]); r++; } nums1.splice(0,nums1.length,...newArr); };