Skip to content

Instantly share code, notes, and snippets.

@masahitojp
Created December 26, 2020 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masahitojp/45bd3abc36d547edae606765961d114b to your computer and use it in GitHub Desktop.
Save masahitojp/45bd3abc36d547edae606765961d114b to your computer and use it in GitHub Desktop.
calc median
# 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