摘要: complete binary tree:除最后一行外每一行的节点都有两个儿子,最后一行的节点尽可能靠左。 ver0: 1 class Solution { 2 public: 3 int countNodes(TreeNode* root) { 4 if(!root) return 0; 5 re 阅读全文
posted @ 2016-02-24 17:24 co0oder 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 void flatten(TreeNode* root) { 4 if(!root) return; 5 flatten(root->left); 6 flatten(root->right); 7 8 TreeNode* right = 阅读全文
posted @ 2016-02-24 16:40 co0oder 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { 4 if(root->val >= p->val && root->val <= q-> 阅读全文
posted @ 2016-02-24 16:17 co0oder 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int rank; 4 int result; 5 6 void help(TreeNode* root, int k){ 7 if(!root) return; 8 9 help(root->left, k); 10 if(++rank 阅读全文
posted @ 2016-02-24 16:04 co0oder 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), 阅读全文
posted @ 2016-02-24 15:59 co0oder 阅读(145) 评论(0) 推荐(0) 编辑