题解 | #买卖股票的最好时机(二)#

买卖股票的最好时机(二)

https://www.nowcoder.com/practice/9e5e3c2603064829b0a0bbfca10594e9

import java.util.*;


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

全部评论

相关推荐

03-24 17:57
门头沟学院 Java
yakuso:你这头像哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务