leetcode462
Posted AsenYang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode462相关的知识,希望对你有一定的参考价值。
public class Solution { public int MinMoves2(int[] nums) { var list = nums.OrderBy(x => x).ToList(); var mid = list[list.Count / 2]; var count = 0; for (int i = 0; i < nums.Length; i++) { var cur = nums[i]; if (cur != mid) { count += Math.Abs(cur - mid); } } return count; } }
https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/#/description
以上是关于leetcode462的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 462. Minimum Moves to Equal Array Elements II
Leetcode-462 Minimum Moves to Equal Array Elements II(最少移动次数使数组元素相等 II)
LeetCode 668. 乘法表中第k小的数 / 462. 最少移动次数使数组元素相等 II / 436. 寻找右区间
462 Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等 II
leetcode_1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_[二维前缀和](代码片段