File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed
s3355_zero_array_transformation_i
s3357_minimize_the_maximum_adjacent_element_difference Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -6,20 +6,30 @@ public class Solution {
6
6
public boolean isZeroArray (int [] nums , int [][] queries ) {
7
7
int n = nums .length ;
8
8
int sum = 0 ;
9
- for (int num : nums ) sum += num ;
10
- if (sum == 0 ) return true ;
9
+ for (int num : nums ) {
10
+ sum += num ;
11
+ }
12
+ if (sum == 0 ) {
13
+ return true ;
14
+ }
11
15
int [] diff = new int [n + 1 ];
12
16
for (int [] q : queries ) {
13
17
int low = q [0 ];
14
18
int high = q [1 ];
15
19
diff [low ] -= 1 ;
16
- if (high + 1 < n ) diff [high + 1 ] += 1 ;
20
+ if (high + 1 < n ) {
21
+ diff [high + 1 ] += 1 ;
22
+ }
17
23
}
18
24
for (int i = 0 ; i < n ; i ++) {
19
- if (i > 0 ) diff [i ] += diff [i - 1 ];
25
+ if (i > 0 ) {
26
+ diff [i ] += diff [i - 1 ];
27
+ }
20
28
nums [i ] += diff [i ];
21
29
sum += diff [i ];
22
- if (nums [i ] > 0 ) return false ;
30
+ if (nums [i ] > 0 ) {
31
+ return false ;
32
+ }
23
33
}
24
34
return sum <= 0 ;
25
35
}
Original file line number Diff line number Diff line change 5
5
public class Solution {
6
6
public int minDifference (int [] nums ) {
7
7
int n = nums .length ;
8
- int max_adj = 0 ;
8
+ int maxAdj = 0 ;
9
9
int mina = Integer .MAX_VALUE ;
10
10
int maxb = Integer .MIN_VALUE ;
11
11
for (int i = 0 ; i < n - 1 ; ++i ) {
12
12
int a = nums [i ];
13
13
int b = nums [i + 1 ];
14
14
if (a > 0 && b > 0 ) {
15
- max_adj = Math .max (max_adj , Math .abs (a - b ));
15
+ maxAdj = Math .max (maxAdj , Math .abs (a - b ));
16
16
} else if (a > 0 || b > 0 ) {
17
17
mina = Math .min (mina , Math .max (a , b ));
18
18
maxb = Math .max (maxb , Math .max (a , b ));
@@ -28,7 +28,8 @@ public int minDifference(int[] nums) {
28
28
while (j < n && nums [j ] == -1 ) {
29
29
j ++;
30
30
}
31
- int a = Integer .MAX_VALUE , b = Integer .MIN_VALUE ;
31
+ int a = Integer .MAX_VALUE ;
32
+ int b = Integer .MIN_VALUE ;
32
33
if (i > 0 ) {
33
34
a = Math .min (a , nums [i - 1 ]);
34
35
b = Math .max (b , nums [i - 1 ]);
@@ -50,6 +51,6 @@ public int minDifference(int[] nums) {
50
51
}
51
52
}
52
53
}
53
- return Math .max (max_adj , (res + 1 ) / 2 );
54
+ return Math .max (maxAdj , (res + 1 ) / 2 );
54
55
}
55
56
}
You can’t perform that action at this time.
0 commit comments