Minimum Number of Increments on Subarrays to Form a Target Array LeetCode solution in C++

1
class Solution {
2
public:
3
int minNumberOperations(vector<int> &target) {
4
int n = target.size();
5
int pre = 0, cnt = 0;
6
for (int i = 0; i < n; i++) {
7
if (target[i] > pre) cnt += target[i] - pre;
8
pre = target[i];
9
}
10
return cnt;
11
}
12
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0