2013年11月16日

Populating Next Right Pointers in Each Node II

摘要: 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 still work?Note:You may only use constant extra space.For example,Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ... 阅读全文

posted @ 2013-11-16 13:39 Step-BY-Step 阅读(162) 评论(0) 推荐(0) 编辑

Path Sum II

摘要: 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 andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[ [5,4,11,2]... 阅读全文

posted @ 2013-11-16 09:06 Step-BY-Step 阅读(166) 评论(0) 推荐(0) 编辑

Convert Sorted Array to Binary Search Tree

摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.balanced tree 是指 tree的 min depth 和max depth不超过某个数值(1)。而不是完全二叉树!!!! 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 ... 阅读全文

posted @ 2013-11-16 07:08 Step-BY-Step 阅读(144) 评论(0) 推荐(0) 编辑

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.和pre & in 是一样的。 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeN... 阅读全文

posted @ 2013-11-16 06:43 Step-BY-Step 阅读(137) 评论(0) 推荐(0) 编辑

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.本来想先对inorder array做预处理存上val对应的index,结果发现 val可能有duplicates。 1 /**duplicates 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * Tr... 阅读全文

posted @ 2013-11-16 06:37 Step-BY-Step 阅读(156) 评论(0) 推荐(0) 编辑

Maximum Depth of Binary Tree

摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.一样的。 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 ... 阅读全文

posted @ 2013-11-16 05:54 Step-BY-Step 阅读(130) 评论(0) 推荐(0) 编辑

Binary Tree Zigzag Level Order Traversal

摘要: Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and al... 阅读全文

posted @ 2013-11-16 05:48 Step-BY-Step 阅读(199) 评论(0) 推荐(0) 编辑

Binary Tree Level Order Traversal

摘要: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]confused what"{1,#,2,3}"means?> read more . 阅读全文

posted @ 2013-11-16 05:18 Step-BY-Step 阅读(190) 评论(0) 推荐(0) 编辑

导航