Range Sum Query - Immutable

class NumArray:

    def __init__(self, nums: List[int]):
        self.pfxsum = [0]
        for n in nums:
            self.pfxsum.append(n + self.pfxsum[-1])

    def sumRange(self, left: int, right: int) -> int:
        return self.pfxsum[1 + right] - self.pfxsum[left]