We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c49180f commit e7b43fbCopy full SHA for e7b43fb
java/0303-range-sum-query-immutable.java
@@ -0,0 +1,23 @@
1
+class NumArray {
2
+
3
+ public int[] arr;
4
+ public NumArray(int[] nums) {
5
+ arr=nums;
6
+ for(int i=1;i<arr.length;i++){
7
+ arr[i]+=arr[i-1];
8
+ }
9
10
11
+ public int sumRange(int left, int right) {
12
+ if(left==0){
13
+ return arr[right];
14
15
+ return arr[right]-arr[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
+ */
0 commit comments