码迷,mamicode.com
首页 >  
搜索关键字:binary    ( 11734个结果
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 tree. 方法 根据树的中序遍历和前序遍历,来构造树,使用递归的思想。 Tre...
分类:其他好文   时间:2014-06-20 12:14:49    阅读次数:262
Convert Sorted Array to Binary Search Tree
题目 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 方法 数组是有序的,要求创建的二叉树尽量平衡,很容易想到对数组进行二分操作,左边的数组元素是左子树,右边的数组元素是右子树。进行递归操作就可以了。 TreeNode...
分类:其他好文   时间:2014-06-20 11:06:46    阅读次数:257
LeetCode: Path Sum II [113]
【题目】 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / 4 8 / / 11 13 4 ...
分类:其他好文   时间:2014-06-20 10:53:08    阅读次数:181
Binary Tree Inorder Traversal
题目 Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 2 / 3 return [1,3,2]. Note: Recur...
分类:其他好文   时间:2014-06-20 10:22:00    阅读次数:221
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. 方法 和有序数组的思想基本一样,将链表进行二分。 TreeNode getBST(ListNode head, int len) { i...
分类:其他好文   时间:2014-06-20 09:46:33    阅读次数:267
Balanced Binary Tree
题目 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node...
分类:其他好文   时间:2014-06-20 09:02:56    阅读次数:232
Construct Binary Tree from Inorder and Postorder Traversal
题目 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 方法 根据树的中序遍历和后序遍历,来恢复树,使用递归的思想。 Tr...
分类:其他好文   时间:2014-06-07 14:50:37    阅读次数:231
LeetCode: Populating Next Right Pointers in Each Node [116]
【题目】 Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be...
分类:其他好文   时间:2014-06-07 14:28:36    阅读次数:215
LeetCode: Path Sum [112]
【题目】 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / ...
分类:其他好文   时间:2014-06-07 13:57:37    阅读次数:210
LeetCode: Flatten Binary Tree to Linked List [114]
【题目】 Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / 2 5 / \ 3 4 6 The flattened tree should look like: 1 2 3 4 \...
分类:其他好文   时间:2014-06-07 11:37:00    阅读次数:153
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!