您的位置:首页 > 其它

Day12 Best Time to Buy and Sell Stock II

2018-02-10 12:29 281 查看
LeetCode122 Best Time to Buy and Sell Stock II
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 as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

与前面一题不同,这里允许多次交易,但是在买入的时候必须卖掉手上的。

思路也很简单,先买第一天的,如果后面一天的价值高,就卖掉手上的,买入第二天的,如果后面一天的价值低,就把手上的股票换成那天的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LeetCode