LeetCode.303/304 Range Sum Query(2) - Immutable
303.题目(求数组子序列元素之和) Given an integer array nums , find the sum of the elements between indices i and j ( i ≤ j ) , inclusive . Example : Given nums = [ - 2 , 0 , 3 , - 5 , 2 , - 1 ] sumRange ( 0 , 2 ) - > 1 sumRange ( 2 , 5 ) - > - 1 sumRange ( 0 , 5 ) - > - 3 Note : You may assume that the array does not change . There are many calls to sumRange function . 303.分析 class NumArray { // 思路:统计每个元素从index=0到当前元素的下表的元素之和 private int [ ] nums ; private int [ ] sums ; public NumArray ( int [ ] nums ) { this . nums = nums ; if ( nums != null && nums . length > 0 ) { sums = new int [ nums . length ] ;