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 7a78fc6 commit 4417cc3
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.ximo.datastructuresinaction.leetcode.solution303;

import com.ximo.datastructuresinaction.segmenttree.SegmentTree;

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


private SegmentTree<Integer> segmentTree;

public NumArray2(int[] nums) {
Integer[] newNums = new Integer[nums.length];
for (int i = 0; i < nums.length; i++) {
newNums[i] = nums[i];
}

segmentTree = new SegmentTree<>(newNums, (next, prev) -> next + prev);
}

public int sumRange(int i, int j) {
return segmentTree.queryRangeClose(i, j);
}


}

0 comments on commit 4417cc3

Please sign in to comment.