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 {
66    public  boolean  isZeroArray (int [] nums , int [][] queries ) {
77        int  n  = nums .length ;
88        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+         }
1115        int [] diff  = new  int [n  + 1 ];
1216        for  (int [] q  : queries ) {
1317            int  low  = q [0 ];
1418            int  high  = q [1 ];
1519            diff [low ] -= 1 ;
16-             if  (high  + 1  < n ) diff [high  + 1 ] += 1 ;
20+             if  (high  + 1  < n ) {
21+                 diff [high  + 1 ] += 1 ;
22+             }
1723        }
1824        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+             }
2028            nums [i ] += diff [i ];
2129            sum  += diff [i ];
22-             if  (nums [i ] > 0 ) return  false ;
30+             if  (nums [i ] > 0 ) {
31+                 return  false ;
32+             }
2333        }
2434        return  sum  <= 0 ;
2535    }
Original file line number Diff line number Diff line change 55public  class  Solution  {
66    public  int  minDifference (int [] nums ) {
77        int  n  = nums .length ;
8-         int  max_adj  = 0 ;
8+         int  maxAdj  = 0 ;
99        int  mina  = Integer .MAX_VALUE ;
1010        int  maxb  = Integer .MIN_VALUE ;
1111        for  (int  i  = 0 ; i  < n  - 1 ; ++i ) {
1212            int  a  = nums [i ];
1313            int  b  = nums [i  + 1 ];
1414            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 ));
1616            } else  if  (a  > 0  || b  > 0 ) {
1717                mina  = Math .min (mina , Math .max (a , b ));
1818                maxb  = Math .max (maxb , Math .max (a , b ));
@@ -28,7 +28,8 @@ public int minDifference(int[] nums) {
2828            while  (j  < n  && nums [j ] == -1 ) {
2929                j ++;
3030            }
31-             int  a  = Integer .MAX_VALUE , b  = Integer .MIN_VALUE ;
31+             int  a  = Integer .MAX_VALUE ;
32+             int  b  = Integer .MIN_VALUE ;
3233            if  (i  > 0 ) {
3334                a  = Math .min (a , nums [i  - 1 ]);
3435                b  = Math .max (b , nums [i  - 1 ]);
@@ -50,6 +51,6 @@ public int minDifference(int[] nums) {
5051                }
5152            }
5253        }
53-         return  Math .max (max_adj , (res  + 1 ) / 2 );
54+         return  Math .max (maxAdj , (res  + 1 ) / 2 );
5455    }
5556}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments