-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeTwoSortedArrays.java
More file actions
42 lines (36 loc) · 991 Bytes
/
MergeTwoSortedArrays.java
File metadata and controls
42 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
37
38
39
40
41
42
public class MergeTwoSortedArrays {
public static void main(String args[]){
int m=0,n=1,i=0,j=0,t=0;
int nums1[] = {0};
int nums2[] = {1};
int arr[] = new int[m+n];
while(i<m || j<n){
if(i<m && j<n){
if(nums1[i]<=nums2[j]){
arr[t] = nums1[i];
i++;
t++;
}
else{
arr[t] = nums2[j];
j++;
t++;
}
}
else if(i<m && j>=n){
arr[t] = nums1[i];
i++;
t++;
}
else if(i>=m && j<n){
arr[t] = nums2[j];
j++;
t++;
}
}
nums1 = arr;
for(int ele: nums1){
System.out.print(ele+" ");
}
}
}