@@ -0,0 +1,910 @@
+import org.junit.Test;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0A%0A/**%0A * https://leetcode.com/problems/range-sum-query-immutable/%0A */%0Apublic class Solution %7B%0A%0A    @Test%0A    public void test() %7B%0A        int%5B%5D nums = new int%5B%5D%7B-2, 0, 3, -5, 2, -1%7D;%0A        NumArray numArray = new NumArray(nums);%0A%0A        assertEquals(1, numArray.sumRange(0, 2));%0A        assertEquals(-1, numArray.sumRange(2, 5));%0A        assertEquals(-3, numArray.sumRange(0, 5));%0A    %7D%0A%0A    public class NumArray %7B%0A        private int%5B%5D accumulates;%0A%0A        public NumArray(int%5B%5D nums) %7B%0A            this.accumulates = new int%5Bnums.length + 1%5D;%0A%0A            accumulates%5B0%5D = 0;%0A            for (int i = 0; i %3C nums.length; i++) %7B%0A                accumulates%5Bi + 1%5D = accumulates%5Bi%5D + nums%5Bi%5D;%0A            %7D%0A        %7D%0A%0A        public int sumRange(int i, int j) %7B%0A            return accumulates%5Bj + 1%5D - accumulates%5Bi%5D;%0A        %7D%0A    %7D%0A%7D%0A

Range Sum Query - Immutable