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).
与前面一题不同,这里允许多次交易,但是在买入的时候必须卖掉手上的。
思路也很简单,先买第一天的,如果后面一天的价值高,就卖掉手上的,买入第二天的,如果后面一天的价值低,就把手上的股票换成那天的。
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 day12:Best Time to Buy and Sell Stock II
- 122.Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II | 股票利润最大化
- leetCode #122 Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- leetCode:Best Time to Buy and Sell Stock II
- LeetCode 30 Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II C 4ms
- #150 Best Time to Buy and Sell Stock II
- LeetCode 123. Best Time to Buy and Sell Stock II,小米2016校招 风口的猪-中国牛市
- 122 Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- Leetcode: Best Time to Buy and Sell Stock II
- LeetCode - BestTimetoBuyandSellStockII
- LeetCode 122: Best Time to Buy and Sell Stock II
- leetcode [Best Time to Buy and Sell Stock II]//待整理多种解法
- 122. Best Time to Buy and Sell Stock II
- leetcode-122 Best Time to Buy and Sell Stock II
- leetcode || 122、Best Time to Buy and Sell Stock II