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