Segment Tree 的基本操作 Segment Tree Build, Segment Tree Query, Segment Tree Modify 必须熟练掌握; 线段树长什么样子,就是上面的样子,注意到数组A并不要求是sort的,range 是index的范围,每个leaf节点就是A中每个element. Interval Sum 思路:其实,这个题目是为了后面的follow
Union Find模板要会背诵; private class UnionFind {private int[] father;private int count;public UnionFind(int n) {this.father = new int[n + 1];for(int i = 0; i <= n; i++) {father[i] = i;}this.count = n;}pub
Lowest Common Ancestor of a Binary Search Tree 思路:这题跟 Lowest Common Ancestor of Binary Tree 一模一样。思路:就是找p的节点在不在左支,或者右支,找到各自左右节点,然后进行比较,如果两者不一样,说明当前的root就是lowest 父节点,如果左边为空,那就都在右边,返回右边的即可,如果右边为空,那就都在左