minimum-moves-to-equal-array-elements
https://leetcode.com/problems/minimum-moves-to-equal-array-elements/
package com.company;
import java.util.*;
class Solution {
    public int minMoves(int[] nums) {
        // 关键是要想到方法
        // 先把第一个和第二个抹平,再把第二个第三个抹平,依次类推
        Arrays.sort(nums);
        int ret = 0;
        int acc = 0;
        for (int i=1; i<nums.length; i++) {
            acc += nums[i] - nums[i-1];
            ret += acc;
        }
        return ret;
    }
}
public class Main {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("Hello!");
        Solution solution = new Solution();
        // Your Codec object will be instantiated and called as such:
        int[] nums = {1,2,3};
        int ret = solution.minMoves(nums);
        System.out.printf("ret:%d\n", ret);
        System.out.println();
    }
}
minimum-moves-to-equal-array-elements的更多相关文章
- [LeetCode] 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 ...
 - LeetCode Minimum Moves to Equal Array Elements II
		
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...
 - LeetCode Minimum Moves to Equal Array Elements
		
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...
 - 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 ...
 - 【leetcode】453. Minimum Moves to Equal Array Elements
		
problem 453. Minimum Moves to Equal Array Elements 相当于把不等于最小值的数字都减到最小值所需要次数的累加和. solution1: class So ...
 - 453. Minimum Moves to Equal Array Elements 一次改2个数,变成统一的
		
[抄题]: Given a non-empty integer array of size n, find the minimum number of moves required to make a ...
 - LeetCode_453. Minimum Moves to Equal Array Elements
		
453. Minimum Moves to Equal Array Elements Easy Given a non-empty integer array of size n, find the ...
 - LeetCode 453. 最小移动次数使数组元素相等(Minimum Moves to Equal Array Elements) 47
		
453. 最小移动次数使数组元素相等 453. Minimum Moves to Equal Array Elements 题目描述 给定一个长度为 n 的非空整数数组,找到让数组所有元素相等的最小移 ...
 - [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等
		
Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...
 - LeetCode 453 Minimum Moves to Equal Array Elements
		
Problem: Given a non-empty integer array of size n, find the minimum number of moves required to mak ...
 
随机推荐
- iis7/7.5设置上传文件最大大小
			
本编今天接到一个客户的修改,说一个68M的pdf文件上传不上去,但是我本地开启断点调试了好几遍,都没有问题,能正常上传文件,由此确定不是代码问题.然后我试着上传5M左右的pdf却能正常的上传,然后上传 ...
 - ObjC的Block中使用weakSelf/strongSelf @weakify/@strongify
			
首先要说说什么时候使用weakSelf和strongSelf. 下面引用一篇博客<到底什么时候才需要在ObjC的Block中使用weakSelf/strongSelf>的内容: Objec ...
 - Sqli-labs less 25
			
Less-25 本关主要为or and过滤,如何绕过or和and过滤.一般性提供以下几种思路: 大小写变形 Or,OR,oR 编码,hex,urlencode 添加注释/*or*/ 利用符号 and= ...
 - Extjs文本输入域
			
var form = Ext.create('Ext.form.Panel', { renderTo: Ext.getBody(), frame: tr ...
 - Windows 7 常用快捷键 命令
			
Win+E: 打开新的windows资源浏览器 Win+F:搜索文件或文件夹 Win+R:打开运行窗口 Win + D:显示桌面 Win + M:最小化所有窗口 Ctrl+Shift+N: 新建文件 ...
 - SQL技术内幕-7 varchar类型的数字和 int 类型的数字的比较+cast的适用
			
DECLARE @x VARCHAR(10); DECLARE @y INT; DECLARE @z VARCHAR(10); SET @x = '1000'; SET @y = '2000'; SE ...
 - AutoCompleteTextView的应用
			
现在我们上网几乎都会用百度或者谷歌搜索信息,当我们在输入框里输入一两个字后,就会自动提示我们想要的信息,这种效果在Android 里是如何实现的呢? 事实上,Android 的AutoComplete ...
 - poj 2068 Nim 博弈论
			
思路:dp[i][j]:第i个人时还剩j个石头. 当j为0时,有必胜为1: 后继中有必败态的为必胜态!!记忆化搜索下就可以了! 代码如下: #include<iostream> #incl ...
 - node入门开发遇到的问题
			
最近在看node入门这本书,https://cnodejs.org/getstart 里面是跟随作者完成一个小的demo,书中不免会有遗漏的,下面是我在实现里面最后一个例子时遇到的问题,希望能够帮助其 ...
 - Struts2 Convention插件的使用(1)
			
刚刚查阅官方文档(convention-plugin.html)并学习了Struts2的Convention插件,文章这里只作为一个笔记,建议大家去看官方文档比较清晰和全面. 需要在项目添加这些包 c ...