Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 1827. Minimum Operations to Make the Array Increasing

Posted on 2021-04-18 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int minOperations(vector<int>& nums) {
int ans = 0, prev = INT_MIN;
for (int num : nums) {
if (num <= prev) {
int next = prev + 1;
ans += next - num;
prev = next;
} else {
prev = num;
}
}
return ans;
}
};
# Greedy# Array
LeetCode 213. House Robber II
LeetCode 1828. Queries on Number of Points Inside a Circle
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%