Created
August 10, 2017 08:47
-
-
Save luojiyin1987/8c4a3563183d584e8195209d25a5b99e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func minMoves(nums []int) int { | |
| sort.Ints(nums) | |
| min := nums[0] | |
| sum :=0 | |
| for _, v := range nums { | |
| sum +=v | |
| } | |
| return sum - min * len(nums) | |
| } | |
| func minMoves(nums []int) int { | |
| min := math.MaxInt32 | |
| for _, n := range nums { | |
| if n < min { | |
| min = n | |
| } | |
| } | |
| res := 0 | |
| for _, n := range nums { | |
| res += n-min | |
| } | |
| return res | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment