问道leetcode上的题# JobHunting - 待字闺中
j*n
1 楼
http://www.leetcode.com/2010/11/best-time-to-buy-and-sell-stock
下面有人给了个新问题:
if you can keep buying and selling, how to maximize the profit? for example,
if it is 6,1,3,2,4,7, we can buy for 1 and sell for 3, and we can buy for 2
, and sell for 4,then buy on 4, sell for 7. total maxval =3-1+4-2+7-4 = 7.
They would like to have some O(n) solutions.
下面有人给了个新问题:
if you can keep buying and selling, how to maximize the profit? for example,
if it is 6,1,3,2,4,7, we can buy for 1 and sell for 3, and we can buy for 2
, and sell for 4,then buy on 4, sell for 7. total maxval =3-1+4-2+7-4 = 7.
They would like to have some O(n) solutions.