Skip to content

Commit cab289e

Browse files
committed
solved leetcode daily challenge, minimum operations to make the array increasing
1 parent 15acf3f commit cab289e

File tree

1 file changed

+60
-0
lines changed
  • LeetCode/Minimum_Operations_to_Make_the_Array_Increasing

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <bits/stdc++.h>
2+
#include <gtest/gtest.h>
3+
using namespace std;
4+
5+
6+
//// START ## Minimum Operations to Make the Array Increasing
7+
8+
9+
/*
10+
* 1 <= nums.length <= 5000
11+
1 <= nums[i] <= 104
12+
*/
13+
class Solution {
14+
public:
15+
int minOperations(vector<int> &nums) {
16+
int ret = 0;
17+
for (int i = 1; i < nums.size(); i++) {
18+
if (nums[i] > nums[i - 1]) continue;
19+
int d = nums[i - 1] - nums[i];
20+
ret += d + 1;
21+
nums[i] += d + 1;
22+
}
23+
return ret;
24+
}
25+
};
26+
27+
28+
//// END
29+
30+
31+
32+
33+
struct T {
34+
35+
};
36+
37+
TEST(Solution, test) {
38+
T ts[] = {
39+
{
40+
41+
},
42+
{
43+
44+
},
45+
46+
};
47+
48+
for (T t : ts) {
49+
Solution solution;
50+
51+
}
52+
}
53+
54+
int main() {
55+
testing::InitGoogleTest();
56+
57+
return RUN_ALL_TESTS();
58+
}
59+
60+

0 commit comments

Comments
 (0)