今際の国の呵呵君
Tuesday, January 27, 2015
[LeetCode]Best Time to Buy and Sell Stock III
结合
Best Time to Buy and Sell Stock
和
Max Subarray II
的解法,左右扫一遍就行,从左到右的DP方程
Best Time to Buy and Sell Stock
是一样的,从右到左就按照
Max Subarray II
的方法反过来就行了,注意这里我们同一天先卖了在买是允许的,只要同一时间手上不超过两个股票就行。时间复杂度课空间复杂度都是O(n),代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment