Created
December 26, 2020 14:13
-
-
Save masahitojp/45bd3abc36d547edae606765961d114b to your computer and use it in GitHub Desktop.
calc median
This file contains hidden or 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
# for leetcode | |
# https://leetcode.com/problems/median-of-two-sorted-arrays/solution/ | |
class Solution: | |
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: | |
c = sorted(nums1 + nums2) | |
l = len(c) | |
ans =0 | |
if l % 2 == 1: | |
ans = c[ l // 2] | |
else: | |
ans = (c[l//2 - 1] + c[l//2]) /2 | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment