Best Time to Buy and Sell Stock II
public int maxProfit(int[] prices) {
// 贪心算法,只要有赚就买
if(prices == null || prices.length == 0 )
return 0;
int diff, profit = 0;//初始化每次都错!!!
for(int i = 1; i < prices.length; i++){
diff = prices[i] - prices[i-1];
if(diff > 0)
profit += diff;
}
return profit;
}Last updated