You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * @param {number[]} A * @param {number} m * @param {number[]} B * @param {number} n * @return {void} Do not return anything, modify A in-place instead. */varmerge=function(A,m,B,n){leti=m+n-1;letAI=m-1;letBI=n-1;while(BI>=0){if(AI>=0&&A[AI]>B[BI]){swap(A,AI,i);AI--;}else{A[i]=B[BI];BI--;}i--;}functionswap(arr,a,b){consttemp=arr[a];arr[a]=arr[b];arr[b]=temp;}};
《程序员面试金典(第 6 版)》10.01. 合并排序的数组
给定两个排序后的数组 A 和 B,其中 A 的末端有足够的缓冲空间容纳 B。 编写一个方法,将 B 合并入 A 并排序。
初始化 A 和 B 的元素数量分别为 m 和 n。
Example 1
Note
A.length == n + m
The text was updated successfully, but these errors were encountered: