Forked from xiaotangyuan/leetcode:4 Median of Two Sorted Arrays
Created
June 29, 2016 09:32
-
-
Save astery/c2ce16c819cdc280aa9d04c164f282a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def findMedianSortedArrays(self, nums1, nums2): | |
""" | |
:type nums1: List[int] | |
:type nums2: List[int] | |
:rtype: float | |
""" | |
nums = nums1 + nums2 | |
nums = sorted(nums) | |
total = len(nums) | |
if total % 2 == 0: | |
return (nums[total/2-1] + nums[total/2]) / 2.0 | |
else: | |
return nums[total/2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment