摘要:
Populating Next Right Pointers in Each Node II2014.1.8 21:00Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given the followin 阅读全文
摘要:
Populating Next Right Pointers in Each Node2014.1.8 05:59Given 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... 阅读全文
摘要:
Path Sum II2014.1.8 05:38Given 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 andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 ... 阅读全文
摘要:
Path Sum2014.1.8 04:59Given 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 andsum = 22, 5 / \ 4 8 / / \ 11... 阅读全文
摘要:
Minimum Depth of Binary Tree2014/1/8 04:29Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Solution: The height of a tree is defined as the longest path from the root node down to the farthe. 阅读全文
摘要:
Balanced Binary Tree2014.1.8 04:09Given 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 ofeverynode never differ by more than 1.Solution: Just do as the problem says, calculate the h. 阅读全文
摘要:
Convert Sorted Array to Binary Search Tree2014.1.8 02:11Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Solution: A height balanced binary tree is a binary tree, whose heights of left and right subtrees varie by at most 1. Thus constructing such a tr. 阅读全文
摘要:
Binary Tree Level Order Traversal II2014.1.8 01:45Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up leve... 阅读全文
摘要:
Construct Binary Tree from Inorder and Postorder Traversal2014.1.8 01:16Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Solution: inorder traversal = left, root, right; postordertraversal = left, right, root; ... 阅读全文
摘要:
Construct Binary Tree from Preorder and Inorder Traversal2014.1.8 00:59Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Solution: preorder traversal = root, left, right; inorder traversal = left, root, right; Th... 阅读全文