题目Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.思路这一次说的是一个普通的二叉树,给出两个节点,求他们的最低公共父节点。
回想一下,当这棵二叉树是二分查找树的时候的解决方案:
二分查找树解法:http://blog.csdn.net/langduhualangd...
分类:
其他好文 时间:
2015-08-11 21:26:38
阅读次数:
114
Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tre...
分类:
其他好文 时间:
2015-08-11 18:58:28
阅读次数:
145
Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
解题思路:
题意为构建有序数组的二分查找树。比较简单,用递归方法即可,中间的元素作为根节点,前半部分作为左孩...
分类:
其他好文 时间:
2015-08-11 18:58:16
阅读次数:
214
Convert Sorted List to Binary Search Tree
Given
a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
解题思路:
题意为构造有序链表的二分查找树。找到中间节点的办法用双指针法。注意我们...
分类:
其他好文 时间:
2015-08-11 18:51:47
阅读次数:
136
Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1
/ 2 5
/ \ 3 4 6
The fl...
分类:
其他好文 时间:
2015-08-11 18:44:03
阅读次数:
110
How Many Trees?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3224 Accepted Submission(s): 1870
Problem Description
A binary search tree...
分类:
其他好文 时间:
2015-08-11 18:42:35
阅读次数:
117
Gray code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 65 Accepted Submission(s): 35
Problem Description
The reflected binary...
分类:
其他好文 时间:
2015-08-11 18:40:38
阅读次数:
109
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr...
分类:
其他好文 时间:
2015-08-11 18:23:52
阅读次数:
95
1043. Is It a Binary Search Tree (25)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left su...
分类:
其他好文 时间:
2015-08-11 16:00:59
阅读次数:
119
5.2 Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represent...
分类:
其他好文 时间:
2015-08-11 15:57:26
阅读次数:
122