Menu Sidebar
Menu

Archive: August 16, 2015

[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; }

[LintCode] Triangle Count

public int triangleCount(int S[]) { // write your code here int res = 0; if(S.length == 0 || S == null) return res; Arrays.sort(S); for(int i = S.length – 1; i > 0; i–) { int l = 0; int r = i – 1; while(l < r) { if(S[l] + S[r] > S[i]){ res […]

书脊

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

August 2015
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31