Skip to content

Commit 30ac1cd

Browse files
committed
Improved 3691
1 parent 8d6158e commit 30ac1cd

File tree

1 file changed

+0
-9
lines changed
  • src/main/java/g3601_3700/s3691_maximum_total_subarray_value_ii

1 file changed

+0
-9
lines changed

src/main/java/g3601_3700/s3691_maximum_total_subarray_value_ii/Solution.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff 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]));

0 commit comments

Comments
 (0)