Leetcode 3422 (就差那么一點(diǎn))
462. 最小操作次數(shù)使數(shù)組元素相等 II
3422. 將子數(shù)組元素變?yōu)橄嗟人璧淖钚〔僮鲾?shù)
# @param {Integer[]} nums
# @return {Integer}
def min_moves2(nums)
l = nums.length
if l%2 == 1
a = nums.sort[l/2]
return nums.map {|it| (it - a).abs}.sum
else
x = nums.sort
a = (x[l/2] + x[l/2 - 1])/2
return nums.map {|it| (it - a).abs}.sum
end
end