coded by C#


  • 0
    I
    public class Solution {
        public double FindMedianSortedArrays(int[] nums1, int[] nums2) {
      
                List<int> temp = new List<int>();
                double media = 0;
                for(int i=0;i<nums1.Length;i++)
                {
                    temp.Add(nums1[i]);
                }
                for(int i=0;i<nums2.Length;i++)
                {
                    temp.Add(nums2[i]);
                }
                temp.Sort();
                if((nums1.Length+nums2.Length)%2==0)
                {
                    media = Convert.ToDouble(temp[temp.Count/2 - 1] + temp[temp.Count/2])/2;
                }
                else
                {
                    media = Convert.ToDouble(temp[temp.Count/2]);
                }
                return media;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.