1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/go/minimum-increment-to-make-array-unique.go
Matej Focko d2ef757754
go: allow testing
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-16 11:44:08 +02:00

17 lines
257 B
Go

package main
import "slices"
func minIncrementForUnique(nums []int) int {
slices.Sort(nums)
moves := 0
for i := 1; i < len(nums); i++ {
if nums[i] <= nums[i-1] {
moves += nums[i-1] + 1 - nums[i]
nums[i] = nums[i-1] + 1
}
}
return moves
}