摘要: 考察点广度优先遍历--层次遍历STL内容器的用法广度优先遍历的时候,首先应该想到的就是借助于队列。还需要在遍历下一层之前保存当前层节点的数量代码很简单:class Solution {public: vector > levelOrderBottom(TreeNode* root) { ... 阅读全文
posted @ 2015-06-03 21:43 hitkb 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 递归左子树是否为平衡二叉树右子树是否为平衡二叉树左右子树高度差是否大于1,大于1,返回false否则判断左右子树最简单的理解方法就是如下的思路:class Solution {public: bool isBalanced(TreeNode* root) { if(root==N... 阅读全文
posted @ 2015-06-03 20:34 hitkb 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 有序链表0->1->2->3->4->5转换为一个二叉排序树。我们在此创建一个平衡二叉排序树1.先找链表到中间的节点2.中间节点的val创建一个新的树节点TreeNode3.将链表断裂为2部分4.递归创建左子树和右子树#include#includeusing namespace std;struc... 阅读全文
posted @ 2015-06-03 20:26 hitkb 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 【LeetCode】Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path fro... 阅读全文
posted @ 2015-01-23 11:18 hitkb 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 在Path SUm 1中(http://www.cnblogs.com/hitkb/p/4242822.html)我们采用栈的形式保存路径,每当找到符合的叶子节点,就将栈内元素输出。注意存在多条路径的情况。 public List> pathSum(TreeNode root, int sum) {... 阅读全文
posted @ 2015-01-23 10:07 hitkb 阅读(197) 评论(0) 推荐(0) 编辑
摘要: Path Sum 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 giv... 阅读全文
posted @ 2015-01-22 22:01 hitkb 阅读(472) 评论(0) 推荐(0) 编辑
摘要: 随笔一记,留做重温!Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 ... 阅读全文
posted @ 2015-01-22 17:10 hitkb 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 编程小记,已供重温!!Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; ... 阅读全文
posted @ 2014-11-29 15:26 hitkb 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 最近想学习一下机器学习方面的知识,在此做一下记录,分享一下学习的一点点收获!参考:http://www.cnblogs.com/LeftNotEasy/archive/2011/03/07/1976562.htmlhttp://www.cnblogs.com/tornadomeet/archiv... 阅读全文
posted @ 2014-11-19 16:41 hitkb 阅读(2846) 评论(0) 推荐(0) 编辑