File tree Expand file tree Collapse file tree 5 files changed +123
-1
lines changed
solution/1800-1899/1827.Minimum Operations to Make the Array Increasing Expand file tree Collapse file tree 5 files changed +123
-1
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,52 @@ public class Solution {
145
145
}
146
146
```
147
147
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
+
148
194
### **...**
149
195
150
196
```
Original file line number Diff line number Diff line change @@ -132,7 +132,6 @@ func max(a, b int) int {
132
132
}
133
133
```
134
134
135
-
136
135
### ** C#**
137
136
138
137
``` cs
@@ -148,6 +147,52 @@ public class Solution {
148
147
}
149
148
```
150
149
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
+
151
196
### **...**
152
197
153
198
```
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments