Untitled

mail@pastecode.io avatar
unknown
python
3 months ago
545 B
1
Indexable
Never
ans = 0
        mid = len(nums)//2
        nums.sort()
       
        if nums[mid] == k:
            return 0
       
        if nums[mid] < k:
            for i in range(mid, len(nums)):
                if nums[i] >= k:
                    break
                   
                ans += abs(k - nums[i])
               
            return ans
       
        if nums[mid] > k:
            i = mid
            while i >= 0 and nums[i] >= k:
                ans += abs(k - nums[i])
                i -= 1
               
            return ans
Leave a Comment