Menu Sidebar
Menu

Segment Tree

[LintCode] Segment Tree Query II

public int query(SegmentTreeNode root, int start, int end) { // write your code here if(root == null || root.end < start || root.start > end) return 0; if(root.start == root.end) return root.count; return query(root.left, start,end)+ query(root.right, start, end); }

[LintCode] Segment Tree Query

public int query(SegmentTreeNode root, int start, int end) { // write your code here if(root == null || root.start > end || root.end < start) return 0; if(root.start == root.end) return root.max; return Math.max(query(root.left,start,end),query(root.right,start,end)); }

[LintCode] Segment Tree Build

public SegmentTreeNode build(int start, int end) { // write your code here if(start > end) return null; SegmentTreeNode root = new SegmentTreeNode(start, end); // root if(start < end) { int mid = start + (end – start) / 2; root.left = build(start, mid); root.right = build(mid+1, end); } return root; }

书脊

这青苔碧瓦堆, 俺曾睡风流觉, 将五十年兴亡看饱.

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930