摘要: 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 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]class Solution 阅读全文
posted @ 2013-07-01 23:55 一只会思考的猪 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.class Solution {public: void f(vector & v, int start, int end, TreeNode *&root){ if (start > end){ return; } int m = start + (end - start)/2; if (!root){ ... 阅读全文
posted @ 2013-07-01 23:24 一只会思考的猪 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.class Solution {public: void f(vector & v, int start, int end, TreeNode *&root){ if (start > end){ return; } int m = start + (end - start)/2; if (!ro... 阅读全文
posted @ 2013-07-01 23:19 一只会思考的猪 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 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 never differ by more than 1.class Solution {public: bool f(TreeNode *root, int & height){ if (!root){ ... 阅读全文
posted @ 2013-07-01 23:01 一只会思考的猪 阅读(132) 评论(0) 推荐(0) 编辑