Leetcode Note: Go - Minimum Operations to Make the Array Increasing

Minimum Operations to Make the Array Increasing - LeetCode
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/

  • Go 言語で取り組んだメモ

回答

Intuitive 6 lines 96.28% Python3/ 100% Go (4 ms!!) - Minimum Operations to Make the Array Increasing - LeetCode
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/solutions/1192463/intuitive-6-lines-96-28-python3-100-go-4-ms/

func minOperations(nums []int) int {
    r := 0; m := 0
    for _, el := range nums {
        if el < m {
            r += m - el + 1; m += 1
        } else if m == el {
            r += 1; m += 1
        } else {
            m = el
        }
    }
    return r
}