Here is the code:
public static int[] Merge(int[] nums1, int[] nums2)
{
int i = 0;
int j = 0;
int k = 0;
int m = nums1.Length;
int n = nums2.Length;
int[] temp = new int[m + n];
while (i < m && j < n)
{
if (nums1[i] < nums2[j])
{
temp[k] = nums1[i];
i++;
}
else
{
temp[k] = nums2[j];
j++;
}
k++;
}
while (i == m && j < n)
{
temp[k] = nums2[j];
j++;
k++;
}
while (j == n && i < m)
{
temp[k] = nums1[i];
i++;
k++;
}
return temp;
}
Your go-to destination for mastering software development technologies, data structures, and algorithms in an easy-to-understand way!
Popular Posts
-
Here is the Code: class Program { static void Main(string[] args) { Quene q = new Quene(); // This...
-
Here is the code: class Program { static List<int> li = new List<int>(); static void Main(string[] args...
-
Here is the code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; ...