04 2014 档案

动态规划小结 - 一维动态规划 - 时间复杂度 O(n),题 [LeetCode] Jump Game,Decode Ways
摘要:引言一维动态规划根据转移方程,复杂度一般有两种情况。func(i) 只和 func(i-1)有关,时间复杂度是O(n),这种情况下空间复杂度往往可以优化为O(1)func(i) 和 func(1~i-1)有关,时间复杂度是O(n*n),这种情况下空间复杂度一般无法优化,依然为O(n)本篇讨论第一种情... 阅读全文

posted @ 2014-04-28 06:35 Felix Fang 阅读(8306) 评论(0) 推荐(0)

[LeetCode] Merge Interval系列,题:Insert Interval,Merge Intervals
摘要:Interval的合并时比较常见的一类题目,网上的Amazon面经上也有面试这道题的记录。这里以LeetCode上的例题做练习。Merge IntervalsGiven a collection of intervals, merge all overlapping intervals.For ex... 阅读全文

posted @ 2014-04-27 06:08 Felix Fang 阅读(606) 评论(0) 推荐(0)

[LeetCode] Simplify Path,文件路径简化,用栈来做
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cas... 阅读全文

posted @ 2014-04-23 04:23 Felix Fang 阅读(444) 评论(0) 推荐(0)

[LeetCode] Sort Colors 对于元素取值有限的数组,只遍历一遍的排序方法
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文

posted @ 2014-04-22 11:10 Felix Fang 阅读(3625) 评论(0) 推荐(0)

[LeetCode] Largest Rectangle in Histogram O(n) 解法详析, Maximal Rectangle
摘要:Largest Rectangle in HistogramGivennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of l... 阅读全文

posted @ 2014-04-20 13:06 Felix Fang 阅读(12413) 评论(3) 推荐(0)

[线索二叉树] [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 阅读(1434) 评论(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 阅读(1552) 评论(0) 推荐(0)

二叉树系列 - [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 阅读(7026) 评论(1) 推荐(0)

[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 阅读(710) 评论(0) 推荐(0)

动态规划小结 - 二维动态规划 - 时间复杂度 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 阅读(5018) 评论(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 阅读(6430) 评论(0) 推荐(0)

[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 阅读(1075) 评论(0) 推荐(0)

二叉树系列 - 二叉树里的最长路径 例 [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 阅读(10910) 评论(0) 推荐(0)

导航