Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

The overall run time complexity should be O(log (m+n)).

&nbsp;
Example 1:

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


Example 2:

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


&nbsp;
Constraints:


	nums1.length == m
	nums2.length == n
	0 &lt;= m &lt;= 1000
	0 &lt;= n &lt;= 1000
	1 &lt;= m + n &lt;= 2000
	-106 &lt;= nums1[i], nums2[i] &lt;= 106


class Solution(object):
    def findMedianSortedArrays(self, nums1, nums2):
        lis = nums1 + nums2
        lis.sort()
        hi = len(lis)
        print(5/2)
        if hi%2 == 0:
            if (lis[hi/2] + lis[hi/2-1])%2 == 0:
                return (lis[hi/2] + lis[hi/2-1] )/2
            return (lis[hi/2] + lis[hi/2-1])/2 + 0.5
        else:
            return lis[hi//2]
class Solution {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        if(nums1.length==1 && nums2.length==1) return (double)(nums1[0]+nums2[0])/2.0;
        int i = 0;
        int j = 0;
        int k = 0;
        int nums[] = new int[nums1.length + nums2.length];
        if(nums1.length !=0 && nums2.length != 0){
          while(i < nums1.length && j < nums2.length){
            if(nums1[i] < nums2[j]){
                nums[k] = nums1[i];
                i++;
                k++;
            }else{
                nums[k] = nums2[j];
                j++;
                k++;
            }
          }
            while(i < nums1.length){
                nums[k] = nums1[i];
                i++;
                k++;
            }
             while(j < nums2.length){
                nums[k] = nums2[j];
                j++;
                k++;
            }
        }
        if(nums1.length==0){
            for(int h: nums2){
                nums[k] = h;
                k++;
            }
        }

        if(nums2.length==0){
            for(int d : nums1){
                nums[k] = d;
                k++;
            }
        }

        int mid = (nums.length / 2);

        if (nums.length % 2 == 0) {
            return ((double) nums[mid] + (double) nums[mid - 1]) / 2.0;
        } else {
            return nums[mid];
        }
    }
}
class Solution {
public:
    
    
    //Merging two arrays :- 
    vector<int> mergeSortedArrays(vector<int>&arr1,vector<int>&arr2){
        int n = arr1.size();
        int m = arr2.size();
        vector<int> ans(m+n);
        int i = 0;
        int j = 0;
        int mainIndex = 0;
        
        while( i < n && j < m ){
            if(arr1[i] <= arr2[j])ans[mainIndex++] = arr1[i++];
            else ans[mainIndex++] = arr2[j++];
        }
        
        while( i < n){
            ans[mainIndex++] = arr1[i++];
        }
        
        while( j < m){
            ans[mainIndex++] = arr2[j++];
        }
        return ans;
    }
    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
        vector<int> ans = mergeSortedArrays(nums1,nums2);
        float median = 0;
        int n = ans.size()-1;
        
        if(n%2 != 0)
         median=(ans[n/2]+ans[(n/2)+1])/2.0; 
        else
            median=ans[n/2]; 
        return median;
        
    }
};
var findMedianSortedArrays = function(nums1, nums2) {
  let nums3 = nums1.concat(nums2).sort((a,b) => a - b)
  if(nums3.length % 2 !== 0) return nums3[(nums3.length-1)/2]
  return (nums3[nums3.length/2] + nums3[nums3.length/2 - 1])/2
};
Median of Two Sorted Arrays