Prefix
Prefix 🌼
303. Range Sum Query - Immutable
Easy
Given an integer array nums, handle multiple queries of the following type:
- Calculate the sum of the elements of
numsbetween indicesleftandrightinclusive whereleft <= right.
Implement the NumArray class:
NumArray(int[] nums)Initializes the object with the integer arraynums.int sumRange(int left, int right)Returns the sum of the elements ofnumsbetween indicesleftandrightinclusive (i.e.nums[left] + nums[left + 1] + ... + nums[right]).
Example 1:
1 | Input |
1 | class NumArray { |
[toc]
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
