public class Solution {
public int MinMoves2(int[] nums) {
var list = nums.OrderBy(x => x).ToList();
var mid = list[list.Count / ];
var count = ;
for (int i = ; 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的更多相关文章

  1. Leetcode-462 Minimum Moves to Equal Array Elements II

    #462.   Minimum Moves to Equal Array Elements II Given a non-empty integer array, find the minimum n ...

  2. [Swift]LeetCode462. 最少移动次数使数组元素相等 II | Minimum Moves to Equal Array Elements II

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

随机推荐

  1. 2017年 ACM Journal Latex templates 新模板生成 acmart.cls 文件

    假定你的文稿在:/user/acmart-master那么cd /user/acmart-masterlatex acmart.ins最后可得到acmart.cls.

  2. How to Change the Size of a Box-Plot Label in MATLAB

    Type "load carsmall" to load a sample data set included with MATLAB. Type "boxplot(Ho ...

  3. Android学习问题记录之open failed EACCES (Permission denied)

    1.问题描述 Android调用相机拍照保存,然后读取保存好的照片,在读取照片时出现异常(该异常是因为没有SD卡的读取权限所致): 11-08 11:07:46.421 8539-8539/com.c ...

  4. linux自学(一)之vmware虚拟机安装

    之前有研究过linux,后来一段时间没有操作了,现在有点陌生,而且当初也没有记录学习内容.现在想从新开始包括虚拟机安装到部署Javaweb项目,把这之间所需要的全都记录下来,以便后边学习参考使用. 虚 ...

  5. log4j 格式详解

    ### 设置### log4j.rootLogger = debug,stdout,D,E ### 输出信息到控制抬 ### log4j.appender.stdout = org.apache.lo ...

  6. sql中的一些函数(长期更新。。)

    前言 在最近看别人的sql的时候,看到一些函数,比如left(),right()等等,好奇是什么意思,查询之后觉得还是挺有用的,特此记录下来.博客会在遇到新的函数的时候定期更新. 正文 1. left ...

  7. Distributed Denial of Service

    Distributed Denial of Service https://www.cnblogs.com/163yun/p/10030890.html 全称Distributed Denial of ...

  8. HttpMessageConvert

    1. 我们先来看看框架会自动注册哪些httpmessageconvert? 在哪个地方开始注册的? 在对mvc:annotation-driven解析的AnnotationDrivenBeanDefi ...

  9. pymongo和mongodbengine之间的区别

    pymongo是一个mongo driver,可以用来连接数据库以及对数据库进行操作,但是是用mongo自己的用来操作数据库的语句进行操作数据库,而mongodbengine就像是sqlalchemy ...

  10. cnpm 私服搭建(基于docker)

    备注:   使用docker-compose 进行安装 1. 代码clone git clone https://github.com/cnpm/cnpmjs.org.git 2. docker bu ...