Skip to content

Commit

Permalink
Create 0303-range-sum-query-immutable.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Saiteja-Basam authored Apr 13, 2023
1 parent c49180f commit e7b43fb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions java/0303-range-sum-query-immutable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class NumArray {

public int[] arr;
public NumArray(int[] nums) {
arr=nums;
for(int i=1;i<arr.length;i++){
arr[i]+=arr[i-1];
}
}

public int sumRange(int left, int right) {
if(left==0){
return arr[right];
}
return arr[right]-arr[left-1];
}
}

/**
* Your NumArray object will be instantiated and called as such:
* NumArray obj = new NumArray(nums);
* int param_1 = obj.sumRange(left,right);
*/

0 comments on commit e7b43fb

Please sign in to comment.