I have a homework ,and which I have tried to solve for serveral hours.
Description:we have 2 sorted array list ,the length of list a is n, the length of list b is m;we assume a and b are already sorted, and that the lists a and b do not contain duplicates.And I thought as following ,but I always get a error:index out of bound .
public static List<Integer> union(List<Integer> list1, List<Integer> list2 ) {
List<Integer> union = new ArrayList<>();
int n1 = 0;
int n2 = 0;
for (int i = 0; i < list1+list2; i++) {
....
}