Given an integer array nums, handle multiple queries of the following type:
Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.
Implement the NumArray class:
NumArray(nums) — Initializes the object with the integer array nums.sumRange(left, right) — Returns the sum of the elements of nums between indices left and right inclusive (i.e., nums[left] + nums[left + 1] + ... + nums[right]).["NumArray","sumRange","sumRange","sumRange"]
[[[-2,0,3,-5,2,-1]],[0,2],[2,5],[0,5]][null, 1, -1, -3]["NumArray","sumRange"]
[[[1]],[0,0]][null, 1]["NumArray","sumRange"]
[[[1,2,3,4,5]],[0,4]][null, 15]1 <= nums.length <= 10^4-10^5 <= nums[i] <= 10^50 <= left <= right < nums.lengthAt most 10^4 calls will be made to sumRangeExpected time complexity: O(1) per query after O(n) preprocessingRun your code to see results
Use Cmd+Enter to run