sums
of length n + 1
, where n
is the length of the input array nums
. Set sums[0]
to 0.sums
array such that sums[i]
is the cumulative sum of nums
from index 0 to i - 1
.sumRange
function to return sums[right + 1] - sums[left]
, which gives the sum of elements between indices left
and right
.