Skip to content

Commit 0256a21

Browse files
authored
Update and rename Range Sum Query_Immutable.java to Range Sum Query Immutable.java
1 parent fa6d3b8 commit 0256a21

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

Easy/Range Sum Query Immutable.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class NumArray {
2+
3+
int[] sumArray;
4+
5+
public NumArray(int[] nums) {
6+
sumArray = new int[nums.length];
7+
int currSum = 0;
8+
for (int i = 0; i < nums.length; i++) {
9+
currSum += nums[i];
10+
sumArray[i] = currSum;
11+
}
12+
}
13+
14+
public int sumRange(int left, int right) {
15+
return sumArray[right] - (left == 0 ? 0 : sumArray[left - 1]);
16+
}
17+
}
18+
19+
/**
20+
* Your NumArray object will be instantiated and called as such:
21+
* NumArray obj = new NumArray(nums);
22+
* int param_1 = obj.sumRange(left,right);
23+
*/

Easy/Range Sum Query_Immutable.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)