Skip to content

Commit 2e1c15c

Browse files
authored
Create minimum-operations-to-make-the-array-increasing.cpp
1 parent e77c679 commit 2e1c15c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int minOperations(vector<int>& nums) {
7+
int result = 0, prev = 0;
8+
for (const auto& curr : nums) {
9+
if (prev < curr) {
10+
prev = curr;
11+
continue;
12+
}
13+
result += (++prev) - curr;
14+
}
15+
return result;
16+
}
17+
};

0 commit comments

Comments
 (0)