2014年4月16日

[线索二叉树] [LeetCode] 不需要栈或者别的辅助空间,完成二叉树的中序遍历。题:Recover Binary Search Tree,Binary Tree Inorder Traversal

摘要: 既上篇关于二叉搜索树的文章后,这篇文章介绍一种针对二叉树的新的中序遍历方式,它的特点是不需要递归或者使用栈,而是纯粹使用循环的方式,完成中序遍历。线索二叉树介绍首先我们引入“线索二叉树”的概念:"A binary tree isthreadedby making all right child po... 阅读全文

posted @ 2014-04-16 01:05 Felix Fang 阅读(1308) 评论(0) 推荐(0) 编辑

二叉树系列 - 二叉搜索树 - [LeetCode] 中序遍历中利用 pre节点避免额外空间。题:Recover Binary Search Tree,Validate Binary Search Tree

摘要: 二叉搜索树是常用的概念,它的定义如下:The left subtree of a node contains only nodes with keysless thanthe node's key.The right subtree of a node contains only nodes wit... 阅读全文

posted @ 2014-04-16 00:39 Felix Fang 阅读(1527) 评论(0) 推荐(0) 编辑

2014年4月9日

二叉树系列 - [LeetCode] Symmetric Tree 判断二叉树是否对称,递归和非递归实现

摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文

posted @ 2014-04-09 11:26 Felix Fang 阅读(7003) 评论(1) 推荐(0) 编辑

2014年4月8日

[LeetCode] Binary Tree Level Order Traversal 与 Binary Tree Zigzag Level Order Traversal,两种按层次遍历树的方式,分别两个队列,两个栈实现

摘要: Binary Tree Level Order TraversalGiven a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).Fo... 阅读全文

posted @ 2014-04-08 11:51 Felix Fang 阅读(695) 评论(0) 推荐(0) 编辑

2014年4月6日

动态规划小结 - 二维动态规划 - 时间复杂度 O(n*n)的棋盘型,题 [LeetCode] Minimum Path Sum,Unique Paths II,Edit Distance

摘要: 引言二维动态规划中最常见的是棋盘型二维动态规划。即func(i, j) 往往只和 func(i-1, j-1), func(i-1, j) 以及 func(i, j-1) 有关这种情况下,时间复杂度 O(n*n),空间复杂度往往可以优化为O(n)例题 1Minimum Path SumGiven a... 阅读全文

posted @ 2014-04-06 06:58 Felix Fang 阅读(4924) 评论(0) 推荐(0) 编辑

[LeetCode] Populating Next Right Pointers in Each Node I, II

摘要: 题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next poi... 阅读全文

posted @ 2014-04-06 05:37 Felix Fang 阅读(6409) 评论(0) 推荐(0) 编辑

2014年4月4日

[LeetCode] 递推思想的美妙 Best Time to Buy and Sell Stock I, II, III O(n) 解法

摘要: 题记:在求最大最小值的类似题目中,递推思想的奇妙之处,在于递推过程也就是比较求值的过程,从而做到一次遍历得到结果。LeetCode 上面的这三道题最能展现递推思想的美丽之处了。题1 Best Time to Buy and Sell StockSay you have an array for wh... 阅读全文

posted @ 2014-04-04 11:28 Felix Fang 阅读(1064) 评论(0) 推荐(0) 编辑

2014年4月1日

二叉树系列 - 二叉树里的最长路径 例 [LeetCode] Binary Tree Maximum Path Sum

摘要: 题目:Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the... 阅读全文

posted @ 2014-04-01 11:59 Felix Fang 阅读(10786) 评论(0) 推荐(0) 编辑

2014年3月30日

[LeetCode] 数组的最长连续数, O(n)解法

摘要: Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4... 阅读全文

posted @ 2014-03-30 11:40 Felix Fang 阅读(2855) 评论(0) 推荐(0) 编辑

[C#] 类型学习笔记三:自定义值类型

摘要: 既前两篇之后,这一篇我们讨论通过struct 关键字自定义值类型。在第一篇已经讨论过值类型的优势,节省空间,不会触发Gargage Collection等等。在对性能要求比较高的场景下,通过struct代替类是不错的选择。那么,比如我们定义一个Point 类型,里面包含两个左边X, Y。 public struct Point { public int X; public int Y; public Point(int x, int y) { X = x; Y = y; ... 阅读全文

posted @ 2014-03-30 08:04 Felix Fang 阅读(5939) 评论(0) 推荐(1) 编辑

导航