Skip to content

Commit e881282

Browse files
authored
Create minimum-number-of-increments-on-subarrays-to-form-a-target-array.cpp
1 parent 2d2b2c2 commit e881282

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int minNumberOperations(vector<int>& target) {
7+
int result = target[0];
8+
for (int i = 1; i < target.size(); ++i) {
9+
result += max(target[i] - target[i - 1], 0);
10+
}
11+
return result;
12+
}
13+
};

0 commit comments

Comments
 (0)