Skip to content

Commit

Permalink
a453
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhengwei committed Feb 27, 2017
1 parent 94f2d9c commit 9796f76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ leetcode 题解

[416. Partition Equal Subset Sum](Solution/401-450/416.md)

[453. Minimum Moves to Equal Array Elements](Solution/451-500/453.md)

24 changes: 24 additions & 0 deletions Solution/451-500/453.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#453. Minimum Moves to Equal Array Elements
[题目链接](https://leetcode.com/problems/minimum-moves-to-equal-array-elements/?tab=Description)
```java
public class Solution {
/*
一共有n个数字,每次有n-1个数字加一,
可以转换为每次有一个数字减一,
这样就可以转换为每个数见到最小数字的总和
*/
public int minMoves(int[] nums) {
int min = Integer.MAX_VALUE;
for (int num : nums) {
if (num < min) {
min = num;
}
}
int moves = 0;
for (int num : nums) {
moves += (num - min);
}
return moves;
}
}
```

0 comments on commit 9796f76

Please sign in to comment.