leetcode462
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的更多相关文章
- 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 ...
- [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 ...
随机推荐
- phpcms v9取消验证码
phpcms/modules/admin/index.php// $code = isset($_POST['code']) && trim($_POST['code']) ? tri ...
- ranch分析学习(一)
Ranch 是一个tcp处理的程序框架.官方的解释 Ranch is a socket acceptor pool for TCP protocols. 主要目的是提供一个方便,易用,高效,稳定的t ...
- ubuntu查看进程端口号及运行的程序
查看进程端口号及运行的程序:netstat -atunp 根据端口号来查看进程号:lsof -i:16031
- pat甲级 1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...
- 《DSP using MATLAB 》示例Example6.3
代码: C0 = 0; B1 = [2 4; 3 1]; A1 = [1 1 0.9; 1 0.4 -0.4]; B2 = [0.5 0.7; 1.5 2.5; 0.8 1]; A2 = [1 -1 ...
- SEO SEM
SEO:搜索引擎优化SEM:搜索引擎营销 SEO排名机制:搜索引擎蜘蛛 权重 算法 排名规则 搜索引擎提交入口: 1.百度搜索网站登入口 2.Google网站登入口 3.360搜索引擎登入入口 4.搜 ...
- dockerize 容器工具集基本使用
基本功能: * 在启动的时候根据环境变量或者模版生成配置文锦啊 * 多日志文件重定向到标准输入输出 * 等待其他服务(tcp,http unix)起来之后在启动主进程 1. 安装 直 ...
- Cocos2d-x学习笔记1
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u014734779/article/details/26077453 1.创建新的cocos2d-x ...
- php array_push 与 $arr[]=$value 性能比较
1.array_push方法 array_push 方法,将一个或多个元素压入数组的末尾. int array_push ( array &$array , mixed $var [, mix ...
- vs2012加载T4MVC模板
(1)在工程项目上右键点击“管理NuGet程序包”,在线搜索T4MVC模板,选择并安装,安装成功后,项目中会添加T4MVC.tt文件及子文件. (2)如果添加了新的控制器,则右击T4MVC.tt文件点 ...