由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - leetcode里Best Time to Buy and Sell Stock III怎么做?
相关主题
Best Time to Buy and Sell Stock III怎么能证明或者保证两个区间没有相交?leetcode: Divide Two Integers 怎么做?
Best Time to Buy and Sell Stock 出三了。。。leetcode上大数乘代码
关于leetcode上那个买卖股票II的问题Multiple opening @ promising big-data startup
我也遇到leetcode上Run Time Error,但在自己的机子能通过leetcode新题Factorial Trailing Zeroes大家都能过oj么?
buy and sell stock II with 手续费leetcode题目视频讲解
Best Time to Buy and Sell Stock II这么简单?G家面经
明天a家onsite大家leetcode做几遍
等了两个月,终于等到G的拒信。(更新面筋)【update】cs小硕 下周g onsite 求祝福
相关话题的讨论汇总
话题: stock话题: buy话题: sell话题: time话题: best
进入JobHunting版参与讨论
1 (共1页)
b****g
发帖数: 192
1
Say you have an array for which the ith element is the price of a given
stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two
transactions.
Note:
You may not engage in multiple transactions at the same time (ie, you must
sell the stock before you buy again).
想不明白 :(
l*****a
发帖数: 14598
2
那里有人贴答案了

two

【在 b****g 的大作中提到】
: Say you have an array for which the ith element is the price of a given
: stock on day i.
: Design an algorithm to find the maximum profit. You may complete at most two
: transactions.
: Note:
: You may not engage in multiple transactions at the same time (ie, you must
: sell the stock before you buy again).
: 想不明白 :(

p*****p
发帖数: 379
3
From I you get the max profit through at most one transaction.
Then based on I's result you can use dp to get the max profit through at
most two.

two

【在 b****g 的大作中提到】
: Say you have an array for which the ith element is the price of a given
: stock on day i.
: Design an algorithm to find the maximum profit. You may complete at most two
: transactions.
: Note:
: You may not engage in multiple transactions at the same time (ie, you must
: sell the stock before you buy again).
: 想不明白 :(

b****g
发帖数: 192
4
谁能给我讲讲题目是什么意思?

【在 l*****a 的大作中提到】
: 那里有人贴答案了
:
: two

c********w
发帖数: 2438
5
就是你最多能做两个transaction
但这两个transaction
第一个transaction的sell date必须早于或者等于第二个transaction的buy date
然后求最大的收益

【在 b****g 的大作中提到】
: 谁能给我讲讲题目是什么意思?
b****g
发帖数: 192
6
谢谢!
貌似做法和下面的题思路差不多。
左扫一遍,右扫一遍,这就属于DP了,然后就行了。
Multiplication of numbers

【在 c********w 的大作中提到】
: 就是你最多能做两个transaction
: 但这两个transaction
: 第一个transaction的sell date必须早于或者等于第二个transaction的buy date
: 然后求最大的收益

s********s
发帖数: 49
7
从头到尾扫一遍得到0..i的max profit
反向再扫一遍得到i..N的max profit
第三遍扫得到最大的sum,基本山是第一种best time to buy stocks的变形。下面这个
链接也有解释,可以参考。
http://tech-wonderland.net/blog/best-time-to-buy-and-sell-stock
1 (共1页)
进入JobHunting版参与讨论
相关主题
【update】cs小硕 下周g onsite 求祝福buy and sell stock II with 手续费
如何做LeetCodeBest Time to Buy and Sell Stock II这么简单?
祝大家新年快乐~~顺便问个关于facebook coding challenge的问题~明天a家onsite
面试题总结(7) - Tree等了两个月,终于等到G的拒信。(更新面筋)
Best Time to Buy and Sell Stock III怎么能证明或者保证两个区间没有相交?leetcode: Divide Two Integers 怎么做?
Best Time to Buy and Sell Stock 出三了。。。leetcode上大数乘代码
关于leetcode上那个买卖股票II的问题Multiple opening @ promising big-data startup
我也遇到leetcode上Run Time Error,但在自己的机子能通过leetcode新题Factorial Trailing Zeroes大家都能过oj么?
相关话题的讨论汇总
话题: stock话题: buy话题: sell话题: time话题: best