-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
executable file
·35 lines (33 loc) · 814 Bytes
/
Solution.java
File metadata and controls
executable file
·35 lines (33 loc) · 814 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
28
29
30
31
32
33
34
35
package $088;
import java.util.ArrayList;
import java.util.List;
/**
* @author Junlan Shuai[shuaijunlan@gmail.com].
* @date Created on 19:51 2018/5/18.
*/
public class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
List<Integer> list = new ArrayList<>(m + n);
int i = 0, j = 0;
while (i < m && j < n){
if (nums1[i] < nums2[j]){
list.add(nums1[i]);
i++;
}else {
list.add(nums2[j]);
j++;
}
}
while (i < m){
list.add(nums1[i]);
i++;
}
while (j < n){
list.add(nums2[j]);
j++;
}
for (int p = 0; p < (m+n); p++){
nums1[p] = list.get(p);
}
}
}