Why subtracr one from median. Python binary search example
Hello folks. I'm solving leetcode question related to binary search everything went smoothly. Until the last line where arr[len(arr)//2-1 I'm trying to access the median of an even array. Why tho subtracted instead of the regular law of median Median = number at the middle + add one to get th3 number after/2 class Solution(object): def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: float """ arr = nums1 + nums2 arr.sort() if len(arr) % 2 != 0: return arr[len(arr)//2] else: return (arr[len(arr)//2] + arr[len(arr)//2-1])*1.00/2 Here's the link of the question ineetcoze https://leetcode.com/problems/median-of-two-sorted-arrays/description/ Any tips?