Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.方法:为了使BST高度平衡,要找链表中的中值作为当前根节点。/** * Defin...
分类:
其他好文 时间:
2014-08-04 20:37:47
阅读次数:
194
问题:判断二叉树是否为镜像二叉树分析:递归判断,根节点单独判断,然后递归左结点和右结点,之后每次一起递归左结点的左结点和右结点的右结点比较,左结点的右结点和右结点的左结点比较/** * Definition for binary tree * struct TreeNode { * int ...
分类:
其他好文 时间:
2014-08-04 17:27:27
阅读次数:
175
Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ 2 5 / \ \ 3 4 6The flattened ...
分类:
其他好文 时间:
2014-08-04 16:59:37
阅读次数:
246
题目: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 on....
分类:
编程语言 时间:
2014-08-04 13:57:17
阅读次数:
242
问题:n个结点总共有多少个二叉搜索树分析:n=1,sum1=1 n=2,sum2=2; n=3,sum3=2(头结点为1)+1(头结点为2)+2(头结点为3) n=4,sum4=5(头结点为1,sum3)+2(头结点为2,sum1*sum2)+2(头结点为3,sum2*sum1)+...
分类:
其他好文 时间:
2014-08-04 13:53:47
阅读次数:
193
问题:判断二叉树是否为平衡二叉树分析:树上的任意结点的左右子树高度差不超过1,则为平衡二叉树。 搜索递归,记录i结点的左子树高度h1和右子树高度h2,则i结点的高度为max(h1,h2)=1,|h1-h2|>1则不平衡/** * Definition for binary tree * str...
分类:
其他好文 时间:
2014-08-04 13:39:57
阅读次数:
183
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 stil...
分类:
其他好文 时间:
2014-08-04 13:32:57
阅读次数:
184
题目: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 ....
分类:
编程语言 时间:
2014-08-04 10:31:57
阅读次数:
239
题目:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题解:二进制加法都是从最低位(从右加到左)。所以对两个字符串要从最后一位开始加,....
分类:
编程语言 时间:
2014-08-04 06:13:36
阅读次数:
291
题目:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total ....
分类:
编程语言 时间:
2014-08-04 04:10:46
阅读次数:
309