Move Zeroes
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).这一个系列,这次是多次交易
思路
比一次交易的思路简单啊
就是两天相减,大于0就累加,小于0不管
代码
int maxProfit(int* prices, int pricesSize) {
if(pricesSize==0) return 0;
int i,j;
int profit = 0;
for(i=0;i<pricesSize-1;i++)
{
int t = prices[i+1]-prices[i];
if(t>0)
profit+=t;
}
return profit;
}