Skip to content

Commit 0dcf0bc

Browse files
authored
Added Minimum Operations to Make the Array Increasing.java
1 parent 4e3224d commit 0dcf0bc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int minOperations(int[] nums) {
3+
int prev = nums[0];
4+
int totalOperations = 0;
5+
for (int i = 1; i < nums.length; i++) {
6+
if (nums[i] <= prev) {
7+
totalOperations += prev - nums[i] + 1;
8+
prev++;
9+
} else {
10+
prev = nums[i];
11+
}
12+
}
13+
return totalOperations;
14+
}
15+
}

0 commit comments

Comments
 (0)