Skip to content

Commit

Permalink
领扣303题目解法
Browse files Browse the repository at this point in the history
  • Loading branch information
Xikl committed Jan 8, 2019
1 parent 05a6930 commit b22b0c7
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ximo.datastructuresinaction.leetcode.solution303;

/**
* @author xikl
* @date 2019/1/8
*/
public class NumArray {

/**
* sum[0] = 0
* sum[i] 等于 前i个元素的和
*/
private int[] sum;

public NumArray(int[] nums) {
sum = new int[nums.length + 1];
sum[0] = 0;

for (int i = 1; i < sum.length; i++) {
sum[i] = sum[i - 1] + nums[i - 1];
}

}

public int sumRange(int i, int j) {
return sum[j + 1] - sum[i];
}


}

0 comments on commit b22b0c7

Please sign in to comment.