2014年12月2日
摘要: 是之前两道题leetcode Best Time to Buy and Sell Stock和leetcode Best Time to Buy and Sell Stock II的加强版。这里要求只能买两次股票。做了一个多小时,试了好多次,终于AC了。思路:找到有可能为断点的地方,也就是出现递减的... 阅读全文
posted @ 2014-12-02 23:39 higerzhang 阅读(338) 评论(0) 推荐(0) 编辑
摘要: 和上一题类似Best Time to Buy and Sell Stock,这里还是用一个数组存每天股票价格,你有很多次买入卖出的机会,但是每次买入要在前一次卖出前。Say you have an array for which theithelement is the price of a giv... 阅读全文
posted @ 2014-12-02 21:45 higerzhang 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 有一个价格数组,对应的位置代表改天股票的价格,你有一次买入和卖出的机会,你如何使得收益最大化。也就是返回profit。Say you have an array for which theithelement is the price of a given stock on dayi.If you ... 阅读全文
posted @ 2014-12-02 21:38 higerzhang 阅读(455) 评论(0) 推荐(0) 编辑
摘要: 给定一个三角数组,找从上到下的最小和,例如:For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11... 阅读全文
posted @ 2014-12-02 12:28 higerzhang 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 和Pascal's Triangle类似,这里是不需要记录所有的,而是给定一个行号,返回那一行的数据就可以了。例如:For example, givenk= 3,Return[1,3,3,1].所以给0的时候返回[1].题目要求O(k)空间,也就是除了要返回的空间外,其他是常数空间。那就用一个tmp... 阅读全文
posted @ 2014-12-02 11:41 higerzhang 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 这题和上一题Populating Next Right Pointers in Each Node的不一样了,这里要求的是普通的树,难度就比较大了。之前是简单的找到左边的最后,和右边的最左链接就可以了。现在存在的问题是可能右边的左右一层不是在最左或者长度不一等等。 1 / ... 阅读全文
posted @ 2014-12-02 00:51 higerzhang 阅读(769) 评论(0) 推荐(0) 编辑