122. Best Time to Buy and Sell Stock II(Done)

来源:互联网 发布:日语中文同声翻译软件 编辑:程序博客网 时间:2024/06/06 07:49

Solution#1

public class Solution {    public int maxProfit(int[] prices) {        if (prices == null || prices.length == 0)             return 0;        int profit = 0;        for (int i = 1; i < prices.length; i++) {            if (prices[i] > prices[i - 1]) {                profit += prices[i] - prices[i - 1];            }        }        return profit;    }}
0 0
原创粉丝点击