File tree 3 files changed +61
-0
lines changed
solution/1100-1199/1144.Decrease Elements To Make Array Zigzag
3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,28 @@ public class Solution {
180
180
}
181
181
```
182
182
183
+ ### ** TypeScript**
184
+
185
+ ``` ts
186
+ function movesToMakeZigzag(nums : number []): number {
187
+ const ans: number [] = Array (2 ).fill (0 );
188
+ const n = nums .length ;
189
+ for (let i = 0 ; i < 2 ; ++ i ) {
190
+ for (let j = i ; j < n ; j += 2 ) {
191
+ let d = 0 ;
192
+ if (j > 0 ) {
193
+ d = Math .max (d , nums [j ] - nums [j - 1 ] + 1 );
194
+ }
195
+ if (j < n - 1 ) {
196
+ d = Math .max (d , nums [j ] - nums [j + 1 ] + 1 );
197
+ }
198
+ ans [i ] += d ;
199
+ }
200
+ }
201
+ return Math .min (... ans );
202
+ }
203
+ ```
204
+
183
205
### ** ...**
184
206
185
207
```
Original file line number Diff line number Diff line change @@ -166,6 +166,28 @@ public class Solution {
166
166
}
167
167
```
168
168
169
+ ### ** TypeScript**
170
+
171
+ ``` ts
172
+ function movesToMakeZigzag(nums : number []): number {
173
+ const ans: number [] = Array (2 ).fill (0 );
174
+ const n = nums .length ;
175
+ for (let i = 0 ; i < 2 ; ++ i ) {
176
+ for (let j = i ; j < n ; j += 2 ) {
177
+ let d = 0 ;
178
+ if (j > 0 ) {
179
+ d = Math .max (d , nums [j ] - nums [j - 1 ] + 1 );
180
+ }
181
+ if (j < n - 1 ) {
182
+ d = Math .max (d , nums [j ] - nums [j + 1 ] + 1 );
183
+ }
184
+ ans [i ] += d ;
185
+ }
186
+ }
187
+ return Math .min (... ans );
188
+ }
189
+ ```
190
+
169
191
### ** ...**
170
192
171
193
```
Original file line number Diff line number Diff line change
1
+ function movesToMakeZigzag ( nums : number [ ] ) : number {
2
+ const ans : number [ ] = Array ( 2 ) . fill ( 0 ) ;
3
+ const n = nums . length ;
4
+ for ( let i = 0 ; i < 2 ; ++ i ) {
5
+ for ( let j = i ; j < n ; j += 2 ) {
6
+ let d = 0 ;
7
+ if ( j > 0 ) {
8
+ d = Math . max ( d , nums [ j ] - nums [ j - 1 ] + 1 ) ;
9
+ }
10
+ if ( j < n - 1 ) {
11
+ d = Math . max ( d , nums [ j ] - nums [ j + 1 ] + 1 ) ;
12
+ }
13
+ ans [ i ] += d ;
14
+ }
15
+ }
16
+ return Math . min ( ...ans ) ;
17
+ }
You can’t perform that action at this time.
0 commit comments