题解 | #合并两个有序的数组#
合并两个有序的数组
https://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665
/** * * @param A int整型一维数组 * @param B int整型一维数组 * @return void */ function merge( A, m, B, n ) { // write code here let indexA = m-1; let indexB = n-1; let index = m+n-1; while(indexA>=0&&indexB>=0){ const a = A[indexA]; const b = B[indexB]; if(a>b){ A[index] = a; indexA--; index--; continue; }else{ A[index] = b; indexB--; index--; continue; } } while(indexB>=0){ A[index] = B[indexB]; index--; indexB--; } return A; } module.exports = { merge : merge };