Skip to content

Latest commit

 

History

History
26 lines (22 loc) · 630 Bytes

Question_1827.md

File metadata and controls

26 lines (22 loc) · 630 Bytes

LeetCode Records - Question 1827 Minimum Operations to Make the Array Increasing

Attempt 1: The next value should be previous value + 1

class Solution {
    public int minOperations(int[] nums) {
        int count = 0;
        int prevVal = nums[0];

        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > prevVal) {
                prevVal = nums[i];
            } else {
                prevVal++;
                count += prevVal - nums[i];
            }
        }

        return count;
    }
}
  • Runtime: 2 ms (Beats: 100.00%)
  • Memory: 44.63 MB (Beats: 85.61%)