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 {
13
13
public SparseTableOp (int [] arr , IntBinaryOperator op ) {
14
14
this .op = op ;
15
15
int n = arr .length ;
16
- if (n == 0 ) {
17
- this .table = new int [0 ][0 ];
18
- return ;
19
- }
20
16
int maxLog = 31 - Integer .numberOfLeadingZeros (n );
21
17
this .table = new int [n ][maxLog + 1 ];
22
18
for (int i = 0 ; i < n ; i ++) {
@@ -30,10 +26,6 @@ public SparseTableOp(int[] arr, IntBinaryOperator op) {
30
26
}
31
27
32
28
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
- }
37
29
int length = right - left + 1 ;
38
30
int k = 31 - Integer .numberOfLeadingZeros (length );
39
31
return op .applyAsInt (table [left ][k ], table [right - (1 << k ) + 1 ][k ]);
@@ -45,7 +37,6 @@ public long maxTotalValue(int[] nums, int k) {
45
37
if (n == 0 || k == 0 ) {
46
38
return 0 ;
47
39
}
48
- // Create sparse tables for O(1) min and max range queries
49
40
SparseTableOp smin = new SparseTableOp (nums , Math ::min );
50
41
SparseTableOp smax = new SparseTableOp (nums , Math ::max );
51
42
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