File tree Expand file tree Collapse file tree 1 file changed +0
-9
lines changed
src/main/java/g3601_3700/s3691_maximum_total_subarray_value_ii Expand file tree Collapse file tree 1 file changed +0
-9
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,6 @@ private static class SparseTableOp {
1313 public SparseTableOp (int [] arr , IntBinaryOperator op ) {
1414 this .op = op ;
1515 int n = arr .length ;
16- if (n == 0 ) {
17- this .table = new int [0 ][0 ];
18- return ;
19- }
2016 int maxLog = 31 - Integer .numberOfLeadingZeros (n );
2117 this .table = new int [n ][maxLog + 1 ];
2218 for (int i = 0 ; i < n ; i ++) {
@@ -30,10 +26,6 @@ public SparseTableOp(int[] arr, IntBinaryOperator op) {
3026 }
3127
3228 public int query (int left , int right ) {
33- if (left > right ) {
34- throw new IllegalArgumentException (
35- "Left index must not be greater than right index." );
36- }
3729 int length = right - left + 1 ;
3830 int k = 31 - Integer .numberOfLeadingZeros (length );
3931 return op .applyAsInt (table [left ][k ], table [right - (1 << k ) + 1 ][k ]);
@@ -45,7 +37,6 @@ public long maxTotalValue(int[] nums, int k) {
4537 if (n == 0 || k == 0 ) {
4638 return 0 ;
4739 }
48- // Create sparse tables for O(1) min and max range queries
4940 SparseTableOp smin = new SparseTableOp (nums , Math ::min );
5041 SparseTableOp smax = new SparseTableOp (nums , Math ::max );
5142 PriorityQueue <long []> pq = new PriorityQueue <>((a , b ) -> Long .compare (b [0 ], a [0 ]));
You can’t perform that action at this time.
0 commit comments