题解 | #合并两个有序的数组#
合并两个有序的数组
http://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665
//使用现成的工具,将数组转化为链表,使用Collections里的sort方法,虽然简单,但是占用内存过多
import java.util.*;
public class Solution {
public void merge(int A[], int m, int B[], int n) {
//first :put the B array's Element into A array
for(int i = 0;i<n;i++){
A[m+i] = B[i];
}
//turn A array to a List
List<Integer>l1 = new ArrayList<>();
for(int temp:A){
l1.add(temp);
}
Collections.sort(l1);
Iterator<Integer> it = l1.iterator();
int i = 0;
while(it.hasNext()){
A[i++] = it.next();
}
}
}