题目来源:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/
思路参考题解:
class Solution {
public int maxProfit(int[] prices) {
if (prices == null||prices.length <2){
return 0;
}
int sumProfit = 0;
for(int i = 1;i<prices.length;i++){
int curProfit = prices[i] - prices[i-1];
if(curProfit>0){
sumProfit += curProfit;
}
}
return sumProfit;
}
}
相似题目:
买卖股票的最佳时机