<p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>

<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,3], nums2 = [2]
<strong>Output:</strong> 2.00000
<strong>Explanation:</strong> merged array = [1,2,3] and median is 2.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,2], nums2 = [3,4]
<strong>Output:</strong> 2.50000
<strong>Explanation:</strong> merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>nums1.length == m</code></li>
	<li><code>nums2.length == n</code></li>
	<li><code>0 &lt;= m &lt;= 1000</code></li>
	<li><code>0 &lt;= n &lt;= 1000</code></li>
	<li><code>1 &lt;= m + n &lt;= 2000</code></li>
	<li><code>-10<sup>6</sup> &lt;= nums1[i], nums2[i] &lt;= 10<sup>6</sup></code></li>
</ul>

class Solution {
public:

    vector<int> mergeArrays(vector<int>&nums1,vector<int>&nums2){
        vector<int> ans;
        int size1 = nums1.size();
        int size2 = nums2.size();
        int index1 = 0;
        int index2 = 0;
        while(index1<size1 || index2<size2){
                if(!(index1<size1)){
                    ans.push_back(nums2[index2]);
                    index2++;
                    continue;
                }
                if(!(index2<size2)){
                    ans.push_back(nums1[index1]);
                    index1++;
                    continue;
                }

                if(nums1[index1] < nums2[index2]){
                    ans.push_back(nums1[index1]);
                    index1++;
                }else{
                    ans.push_back(nums2[index2]);
                    index2++;
                }
        }
        return ans;
    }

    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2){
       vector<int> mergedArray = mergeArrays(nums1,nums2);
       double ans = 00.00;
       if(mergedArray.size() % 2 == 0){
        ans =  static_cast<double>(mergedArray[(mergedArray.size()/2) - 1] + mergedArray[(mergedArray.size()/2)])/2;
       }else{
        ans =  mergedArray[(mergedArray.size()/2)];
       }
       return ans;
    }
};
95300