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 &lt;= right.


Implement the NumArray class:


	NumArray(int[] nums) Initializes the object with the integer array nums.
	int sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).


&nbsp;
Example 1:

Input
["NumArray", "sumRange", "sumRange", "sumRange"]
[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]
Output
[null, 1, -1, -3]

Explanation
NumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);
numArray.sumRange(0, 2); // return (-2) + 0 + 3 = 1
numArray.sumRange(2, 5); // return 3 + (-5) + 2 + (-1) = -1
numArray.sumRange(0, 5); // return (-2) + 0 + 3 + (-5) + 2 + (-1) = -3


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 104
	-105 &lt;= nums[i] &lt;= 105
	0 &lt;= left &lt;= right &lt; nums.length
	At most 104 calls will be made to sumRange.


class NumArray:

    def __init__(self, nums: List[int]):
        self.nums, Sum = [], 0
        for num in nums:
            Sum += num
            self.nums.append(Sum)

    def sumRange(self, left: int, right: int) -> int:
        return self.nums[right] - self.nums[left - 1] if left - 1 >= 0 else self.nums[right]
class NumArray {
    int [] prefix;
    public NumArray(int[] nums) {
        int n = nums.length;
        prefix = new int[n];
        prefix[0] = nums[0];
        for(int i = 1; i < n; i++){
            prefix[i] = nums[i] + prefix[i - 1];
        }
    }

    public int sumRange(int left, int right) {
        if(left == 0){
            return prefix[right];
        }
        return prefix[right] - prefix[left - 1];
    }
}
class NumArray {
public:
	vector<int>arr;
	NumArray(vector<int>& nums) {
		arr=nums;
	}

	int sumRange(int left, int right) {
		int sum=0;
		for(int i=left;i<=right;i++) sum+=arr[i];
		return sum;
	}
};
var NumArray = function(nums) {
    this.nums = nums;
};

NumArray.prototype.sumRange = function(left, right) {
    let sum = 0;
    for(let i = left; i <= right; i++) sum += this.nums[i]
    return sum
};
Range Sum Query - Immutable