Daily LeetCode – day0135 1827. Minimum Operations to Make the Array Increasing

// 1827. Minimum Operations to Make the Array Increasing
class Solution {
    public int minOperations(int[] nums) {
        int len = nums.length;
        int ans = 0;
        int current = nums[0];
        for (int i = 1; i < len; ++i) {
            ++current;
            if (nums[i] < current) {
                ans += current - nums[i];
            } else {
                current = nums[i];
            }
        }
        return ans;
    }
}
学习笔记:
这是一道简单题,数组题。
就是需要一直递增,遇到大的就很自然,小的就要提升。


关于樊轶群

一个善良的理想主义者。
此条目发表在每日LeetCode分类目录。将固定链接加入收藏夹。

Daily LeetCode – day0135 1827. Minimum Operations to Make the Array Increasing》有一条回应

  1. Milwaukeemdj说:

    LeetCode is the best platform to help you enhance your skills, expand your knowledge and prepare for technical interviews.

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注