https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/ 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 k transactions. Solution global(n, k) 表示前n天中一...
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 ...
temp= prices[i] - prices[i-1]iftemp <=0:continueelse: res+=tempreturnres 参考: 下面的更快,因为索引查找的次数少一些! classSolution(object):defmaxProfit(self, prices):""":type prices: List[int] :rtype: int"""iflen(prices) ==0:return0else: profit=0 start=prices[0]foriinrange(1,...
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). ...
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 ...