@@ -0,0 +1,1062 @@
+package leetcode301_310;%0A%0A/**Given an integer array nums, find the sum of the elements between indices i and j (i %E2%89%A4 j), inclusive.%0A%0A Example:%0A Given nums = %5B-2, 0, 3, -5, 2, -1%5D%0A sumRange(0, 2) -%3E 1%0A sumRange(2, 5) -%3E -1%0A sumRange(0, 5) -%3E -3%0A Note:%0A You may assume that the array does not change.%0A There are many calls to sumRange function.%0A * Created by eugene on 16/6/3.%0A */%0Apublic class RangeSumQueryImmutable %7B%0A%0A    public class NumArray %7B%0A        private int%5B%5D sums;%0A        public NumArray(int%5B%5D nums) %7B%0A            this.sums = new int%5Bnums.length%5D;%0A            if (nums==null %7C%7C nums.length==0) return;%0A            sums%5B0%5D = nums%5B0%5D;%0A            for (int i=1; i%3Cnums.length; i++)%7B%0A                sums%5Bi%5D = sums%5Bi-1%5D+nums%5Bi%5D;%0A            %7D%0A        %7D%0A%0A        public int sumRange(int i, int j) %7B%0A            if (i==0) return sums%5Bj%5D;%0A            return sums%5Bj%5D-sums%5Bi-1%5D;%0A        %7D%0A    %7D%0A%0A// Your NumArray object will be instantiated and called as such:%0A// NumArray numArray = new NumArray(nums);%0A// numArray.sumRange(0, 1);%0A// numArray.sumRange(1, 2);%0A%7D%0A

Range Sum Query - Immutable