题目来源: http://poj.org/problem?id=2255 题目描述: Description Little Valentine liked playing with binary trees very much. Her favorite game was constructing ...
分类:
其他好文 时间:
2018-01-25 00:29:17
阅读次数:
171
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's ...
分类:
其他好文 时间:
2018-01-24 22:11:50
阅读次数:
118
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only ...
分类:
其他好文 时间:
2018-01-24 19:56:13
阅读次数:
164
/* 先序遍历构建链表,重新构建树 */ LinkedList list = new LinkedList(); public void flatten(TreeNode root) { preOrder(root); TreeNode res = root; list.poll(); while ... ...
分类:
其他好文 时间:
2018-01-24 14:03:05
阅读次数:
173
Unique Binary Search Trees II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/unique binary search trees ii/description/ Description Given an integer ...
分类:
其他好文 时间:
2018-01-23 23:20:29
阅读次数:
189
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 whic ...
分类:
其他好文 时间:
2018-01-23 22:12:05
阅读次数:
204
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST' ...
分类:
其他好文 时间:
2018-01-23 14:32:18
阅读次数:
146
这次是二叉搜索树的遍历 感觉只要和二叉搜索树的题目,都要用到一个重要性质: 中序遍历二叉搜索树的结果是一个递增序列; 而且要注意,在递归遍历树的时候,有些参数如果是要随递归不断更新(也就是如果递归返回上层,参数也需要最新的),就要用全局变量,而不是传参,其实这就是全局变量的定义。 不过如果是保存每层 ...
分类:
其他好文 时间:
2018-01-22 17:37:12
阅读次数:
139
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution sti ...
分类:
其他好文 时间:
2018-01-22 13:08:01
阅读次数:
118