Skip to content

Commit 7f70735

Browse files
committed
feat: add solutions to lc problem: No.1827
No.1827.Minimum Operations to Make the Array Increasing
1 parent 4ec6714 commit 7f70735

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed

solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,52 @@ public class Solution {
145145
}
146146
```
147147

148+
### **TypeScript**
149+
150+
```ts
151+
function minOperations(nums: number[]): number {
152+
let ans = 0;
153+
let max = 0;
154+
for (const v of nums) {
155+
ans += Math.max(0, max + 1 - v);
156+
max = Math.max(max + 1, v);
157+
}
158+
return ans;
159+
}
160+
```
161+
162+
### **Rust**
163+
164+
```rust
165+
impl Solution {
166+
pub fn min_operations(nums: Vec<i32>) -> i32 {
167+
let mut ans = 0;
168+
let mut max = 0;
169+
for &v in nums.iter() {
170+
ans += 0.max(max + 1 - v);
171+
max = v.max(max + 1);
172+
}
173+
ans
174+
}
175+
}
176+
```
177+
178+
### **C**
179+
180+
```c
181+
#define max(a, b) (((a) > (b)) ? (a) : (b))
182+
183+
int minOperations(int *nums, int numsSize) {
184+
int ans = 0;
185+
int mx = 0;
186+
for (int i = 0; i < numsSize; i++) {
187+
ans += max(0, mx + 1 - nums[i]);
188+
mx = max(mx + 1, nums[i]);
189+
}
190+
return ans;
191+
}
192+
```
193+
148194
### **...**
149195
150196
```

solution/1800-1899/1827.Minimum Operations to Make the Array Increasing/README_EN.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ func max(a, b int) int {
132132
}
133133
```
134134

135-
136135
### **C#**
137136

138137
```cs
@@ -148,6 +147,52 @@ public class Solution {
148147
}
149148
```
150149

150+
### **TypeScript**
151+
152+
```ts
153+
function minOperations(nums: number[]): number {
154+
let ans = 0;
155+
let max = 0;
156+
for (const v of nums) {
157+
ans += Math.max(0, max + 1 - v);
158+
max = Math.max(max + 1, v);
159+
}
160+
return ans;
161+
}
162+
```
163+
164+
### **Rust**
165+
166+
```rust
167+
impl Solution {
168+
pub fn min_operations(nums: Vec<i32>) -> i32 {
169+
let mut ans = 0;
170+
let mut max = 0;
171+
for &v in nums.iter() {
172+
ans += 0.max(max + 1 - v);
173+
max = v.max(max + 1);
174+
}
175+
ans
176+
}
177+
}
178+
```
179+
180+
### **C**
181+
182+
```c
183+
#define max(a, b) (((a) > (b)) ? (a) : (b))
184+
185+
int minOperations(int *nums, int numsSize) {
186+
int ans = 0;
187+
int mx = 0;
188+
for (int i = 0; i < numsSize; i++) {
189+
ans += max(0, mx + 1 - nums[i]);
190+
mx = max(mx + 1, nums[i]);
191+
}
192+
return ans;
193+
}
194+
```
195+
151196
### **...**
152197
153198
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#define max(a, b) (((a) > (b)) ? (a) : (b))
2+
3+
int minOperations(int *nums, int numsSize) {
4+
int ans = 0;
5+
int mx = 0;
6+
for (int i = 0; i < numsSize; i++) {
7+
ans += max(0, mx + 1 - nums[i]);
8+
mx = max(mx + 1, nums[i]);
9+
}
10+
return ans;
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
pub fn min_operations(nums: Vec<i32>) -> i32 {
3+
let mut ans = 0;
4+
let mut max = 0;
5+
for &v in nums.iter() {
6+
ans += 0.max(max + 1 - v);
7+
max = v.max(max + 1);
8+
}
9+
ans
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function minOperations(nums: number[]): number {
2+
let ans = 0;
3+
let max = 0;
4+
for (const v of nums) {
5+
ans += Math.max(0, max + 1 - v);
6+
max = Math.max(max + 1, v);
7+
}
8+
return ans;
9+
}

0 commit comments

Comments
 (0)