-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path88.java
More file actions
38 lines (36 loc) · 991 Bytes
/
88.java
File metadata and controls
38 lines (36 loc) · 991 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
36
class Solution {
public static void merge(int[] nums1, int m, int[] nums2, int n) {
int[] nums3 = nums1.clone();
int i = 0;
int j = 0;
int curr = 0;
if (n == 0 || m == 0){
if(m==0){
nums1 = nums2;
}
return;
}
while(curr < nums1.length){
var e1 = -1;
var e2 = -1;
if (i < m && j < n){
e1 = nums3[i];
e2 = nums2[j];
}
if (e1 < e2 && e1 > 0){
nums1[curr] = e1;
i++;
}
else{
nums1[curr] = e2;
j++;
}
curr++;
}
}
public static void main(String[] args){
int[] a = {0};
int[] b = {1};
merge(a, 0, b, 1);
}
}