Skip to content

Commit

Permalink
Leetcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Shantanugupta1118 committed Jul 11, 2021
1 parent be2afe1 commit 750c9ae
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Day 55/4. Median of Two Sorted Arrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Github: Shantanugupta1118
# DAY 55 of DAY 100
# 4. Median of Two Sorted Arrays - Leetcode
# https://leetcode.com/problems/median-of-two-sorted-arrays/


class Solution:
def findMedianSortedArrays(self, nums1, nums2):
new_list = sorted(nums1+nums2)
n = len(new_list)
if n%2!=0:
return float(new_list[n//2])

else:
mid1 = new_list[(n-1)//2]
mid2 = new_list[(n+1)//2]
return 0.5*(mid1+mid2)



nums1 = [1,3,6,5,4]
nums2 = [2,5,8,9,12]
print(Solution().findMedianSortedArrays(nums1, nums2))

0 comments on commit 750c9ae

Please sign in to comment.