Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2541 from aadil42/patch-43
Browse files Browse the repository at this point in the history
Create 0303-range-sum-query-immutable.js
  • Loading branch information
aakhtar3 authored Jul 1, 2023
2 parents 9ea6870 + 1b4919f commit 9148768
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions javascript/0303-range-sum-query-immutable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* https://leetcode.com/problems/range-sum-query-immutable/
* @param {number[]} nums
*/
class NumArray {
constructor(nums) {
this.arr = nums;
}

/**
* Time O(n) | Space O(1)
* @param {number} left
* @param {number} right
* @return {number}
*/
sumRange(left, right) {
let total = 0;
for (let i = left; i < right + 1; i++) {
total += this.arr[i];
}
return total;
}
}

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

0 comments on commit 9148768

Please sign in to comment.