摘要: Given a binary tree, return the bottom-up level order traversal 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 7 return its bottom-up level order traversal as: [ [15,7] [9,20], ... 阅读全文
posted @ 2014-04-07 11:33 beehard 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the level order traversal 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 7 return its level order traversal as: [ [3], [9,20], [15,7] ] Solution: 1. Use queue. I... 阅读全文
posted @ 2014-04-07 10:11 beehard 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 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 / \ / \7 2 5 1 return [ [5,4,11,2], [5,8,4,5] ] Solution: DFS. 1 /** 2 * Defini... 阅读全文
posted @ 2014-04-07 09:41 beehard 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 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 / \ 4 8 / / \11 13 4/ \ \ 7... 阅读全文
posted @ 2014-04-07 02:29 beehard 阅读(80) 评论(0) 推荐(0) 编辑
摘要: 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 only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the lef 阅读全文
posted @ 2014-04-07 02:18 beehard 阅读(102) 评论(0) 推荐(0) 编辑