Below is the leetcode question: "problem is when use sort concat any other method on nums1, it is bot modifying nums1 unless I'm emptying it and pushing new data. Below code is working but what if I dont want to create nums11 and perform every method on nums1."
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.
Merge nums1 and nums2 into a single array sorted in non-decreasing order.
The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.
var merge = function(nums1, m, nums2, n) {
let nums11 = [];
for(let i = 0; i<m; i++){
nums11.push(nums1[i])
}
nums1.length = 0;
nums11 = nums11.concat(nums2);
nums11.sort((a,b) => { return a-b});
for(let i = 0; i<nums11.length;i++){
nums1.push(nums11[i])
}
};