3107. Minimum Operations to Make Median of Array Equal to K
You are given an integer array
nums
and a non-negative integerk
. In one operation, you can increase or decrease any element by 1.Return the minimum number of operations needed to make the median of
nums
equal tok
.The median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.
1 | class Solution { |