题解 | #合并两个有序的数组#
合并两个有序的数组
https://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665
import java.util.*; public class Solution { public void merge(int A[], int m, int B[], int n) { int[]res = new int[m+n]; int index = 0; int i = 0,j = 0; while(i < m && j < n) { if (A[i] <= B[j]) { res[index++] = A[i]; i++; } else { res[index++] = B[j]; j++; } } while(index < m + n) { res[index++] = i == m ? B[j++] : A[i++]; } for(int k = 0;k < m+n;k++) { A[k] = res[k]; } } }