Skip to content

Commit 5282b04

Browse files
solves range sum query immutable
1 parent 8e47a79 commit 5282b04

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/RangeSumQueryImmutable.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class RangeSumQueryImmutable {
2+
private static class NumArray {
3+
private final int[] result;
4+
5+
public NumArray(int[] array) {
6+
result = new int[array.length + 1];
7+
for (int index = 0 ; index < array.length ; index++) {
8+
result[index + 1] = result[index] + array[index];
9+
}
10+
}
11+
12+
public int sumRange(int i, int j) {
13+
return result[j] - result[i];
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)