Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia ...
分类:
其他好文 时间:
2016-09-04 14:22:07
阅读次数:
146
Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target. Note: Given target value is a floati ...
分类:
其他好文 时间:
2016-09-03 08:35:21
阅读次数:
140
Validate BST是指按中序遍历niorder后左<node<右; 第一种方法: 先按inoreder遍历, 再放进ArrayList里用循环看是不是从小到大排序; 注意: 设置成员变量list时,如果先new作ArrayList, 则在main函数里每次用都得new个新的class对象; 如 ...
分类:
其他好文 时间:
2016-09-01 07:03:14
阅读次数:
140
Unique Binary Search Trees:求生成二叉排序树的个数。 Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n ...
分类:
编程语言 时间:
2016-08-31 20:39:34
阅读次数:
166
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 给出一个所有元素以升序排序的单链表,将它转换成一棵高度平衡的二分查找树 ...
分类:
其他好文 时间:
2016-08-29 12:36:11
阅读次数:
152
一. BST BST即二叉搜索树Binary Search Tree(又叫二叉排序树Binary Sort Tree)。它有以下特点: BST的搜索,从根结点开始,如果查询的关键字与结点的关键字相等,那么就命中;否则,如果查询关键字比结点关键字小,就进入左儿子;如果比结点关键字大,就进入右儿子;如果 ...
分类:
其他好文 时间:
2016-08-26 12:11:38
阅读次数:
255
Question:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
把有序数组转化成平衡的BST
Algorithm:
找到数组中间的元素,作为根节点,则根节点左边是左子树,根节点右边是右子树,接着递归
Accepted Co...
分类:
其他好文 时间:
2016-08-24 09:58:55
阅读次数:
161
Question:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
把有序链表转化成平衡的BST
Algorithm:
把链表转化成数组,再根据leetcode
No108. Convert Sort...
分类:
其他好文 时间:
2016-08-24 09:57:42
阅读次数:
164
题目链接: 1588: [HNOI2002]营业额统计 Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况。 Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额。分析营业情况是一项相当复杂的工作 ...
分类:
其他好文 时间:
2016-08-22 19:41:45
阅读次数:
203
一定一定要记住tree inorder traversal,很多变种题! pocketGems的面经 ...
分类:
其他好文 时间:
2016-08-22 07:07:36
阅读次数:
144