[LintCode] Best Time to Buy and Sell Stock II
public int maxProfit(int[] prices) { // write your code here int max = 0; for(int i = 1; i < prices.length; i++) { if(prices[i] - prices[i-1] > 0) max += prices[i] - prices[i-1]; } return max; }
public int maxProfit(int[] prices) { // write your code here int max = 0; for(int i = 1; i < prices.length; i++) { if(prices[i] - prices[i-1] > 0) max += prices[i] - prices[i-1]; } return max; }
Leave A Comment