问题描述
Given two sorted integer arrays A and B, merge B into A as one sorted array.
Note:
You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.
问题分析
其实考察的是归并排序,但是更加简便的方法就是两个数组合在一处再排序,虽然能AC,但不符合算法的要求
代码非正确方法实现
public void merge(int A[], int m, int B[], int n) {
for (int i = 0; i < n; i++) {
A[i + m] = B[i];
}
Arrays.sort(A);
}
网友评论