Skip to content

Commit 80f2bdf

Browse files
committed
minimum moves to equal array elements
1 parent f6b4913 commit 80f2bdf

File tree

3 files changed

+93
-39
lines changed

3 files changed

+93
-39
lines changed

.idea/workspace.xml

Lines changed: 68 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ codes may not be optimized
401401
### Day 19 - Easy
402402

403403
1. [Path Sum III](https://leetcode.com/problems/path-sum-iii/description/)
404+
1. [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements/description/)
404405

405406
### Day 19 - Medium
406407

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.chen0040.leetcode.day19.easy;
2+
3+
4+
/**
5+
* Created by xschen on 14/8/2017.
6+
*
7+
* link: https://leetcode.com/problems/minimum-moves-to-equal-array-elements/description/
8+
*/
9+
public class MinimumMovesToEqualArrayElements {
10+
public class Solution {
11+
public int minMoves(int[] nums) {
12+
int min = Integer.MAX_VALUE;
13+
for(int i=0; i < nums.length; ++i) {
14+
min = Math.min(min, nums[i]);
15+
}
16+
int sum = 0;
17+
for(Integer i : nums) {
18+
sum += (i - min);
19+
}
20+
return sum;
21+
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)