Best Time to Buy and Sell Stock II

来源:互联网 发布:互通商城 软件靠谱吗 编辑:程序博客网 时间:2024/06/17 17:34

我就是一只勤劳的小蜜蜂啊O(∩_∩)O哈哈~

木有测试用例很容易理解错误题意滴。。。

public class Solution {    public int maxProfit(int[] prices) {                int profit = 0;        int pre = 0;        for(int i = 1; i < prices.length; i++){            if(prices[i] > prices[pre]){                profit += prices[i] - prices[pre];            }            pre = i;        }        return profit;    }}

0 0
原创粉丝点击