-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasy_88.java
More file actions
27 lines (22 loc) · 771 Bytes
/
easy_88.java
File metadata and controls
27 lines (22 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 88. Merge Sorted Array
import java.util.*;
public class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
ArrayList<Integer> sortedNums1 = sort(Arrays.copyOf(nums1, m));
ArrayList<Integer> sortedNums2 = sort(Arrays.copyOf(nums2, n));
sortedNums1.addAll(sortedNums2);
Collections.sort(sortedNums1);
for (int i = 0; i < sortedNums1.size(); i++) {
nums1[i] = sortedNums1.get(i);
}
System.out.println(sortedNums1);
}
public ArrayList<Integer> sort(int[] list) {
ArrayList<Integer> mutable = new ArrayList<>();
for (int num : list) {
mutable.add(num);
}
Collections.sort(mutable);
return mutable;
}
}