Best Time to buy and sell II

public class Solution {
    /**
     * @param prices: Given an integer array
     * @return: Maximum profit
     */
			public int maxProfit(int[] prices) {
				int profit = 0;
				for (int i = 0; i < prices.length - 1; i++) {
					int diff = prices[i + 1] - prices[i];
			if (diff > 0) profit += diff; 
				}
				return profit;
			}
}

最后更新于

这有帮助吗?