Short C# solution, nearly no algo, just use something .net includes!


  • -1
    E
    public class Solution {
    public double FindMedianSortedArrays(int[] nums1, int[] nums2)
        {
            List<int> nums = new List<int>();
            nums.AddRange(nums1);
            nums.AddRange(nums2);
            nums.Sort();
            double ans = 0.0;
            if (nums.Count % 2 == 0)
                return ans = (nums[(nums.Count + 1) / 2 - 1] + nums[(nums.Count + 1) / 2]) / 2.0;
            else
                return ans = nums[nums.Count / 2] * 1.0;
        }
    

    }


Log in to reply
 

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