classNumArray(object):def__init__(self,nums):""" initialize your data structure here. :type nums: List[int] """n=len(nums)self.sums=[0]*(n+1)foriinrange(n):self.sums[i+1]=self.sums[i]+nums[i]defsumRange(self,i,j):""" sum of elements nums[i..j], inclusive. :type i: int :type j: int :rtype: int """returnself.sums[j+1]-self.sums[i]# Your NumArray object will be instantiated and called as such:# numArray = NumArray(nums)# numArray.sumRange(0, 1)# numArray.sumRange(1, 2)