We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c2b2118 commit f63ed41Copy full SHA for f63ed41
MergeArraysSorted.java
@@ -0,0 +1,36 @@
1
+package ds.algo.solution;
2
+
3
+public class MergeArraysSorted {
4
5
+ public int[] merge(int[] arr1, int[] arr2) {
6
7
+ int arr1Len = arr1.length;
8
+ int arr2Len = arr2.length;
9
+ int i = 0, x = 0, y = 0;
10
11
+ int[] resultArr = new int[arr1Len + arr2Len];
12
13
+ while (x < arr1Len && y < arr2Len) {
14
+ if(arr1[x] < arr2[y]) {
15
+ resultArr[i] = arr1[x];
16
+ x++;
17
+ }
18
+ else {
19
+ resultArr[i] = arr2[y];
20
+ y++;
21
22
23
+ i++;
24
25
26
+ for (int q = x; q < arr1.length; q++) {
27
+ resultArr[i++] = arr1[q];
28
29
30
+ for (int q = y; q < arr2.length; q++) {
31
+ resultArr[i++] = arr2[q];
32
33
34
+ return resultArr;
35
36
+}
0 commit comments