标签:list var blog script .com tps ref lis array
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
标签:list var blog script .com tps ref lis array
原文地址:http://www.cnblogs.com/asenyang/p/6831017.html