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

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

https://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec

    public int maxProfit (int[] prices) {
        // write code here
        int max = 0;
        for(int i = 0; i < prices.length - 1; i ++){
            for(int j = i; j <= prices.length -1; j++){
                if(prices[i] < prices[j]){
                    int tmp = prices[j] - prices[i];
                    if(tmp > max) max = tmp;
                }
            }
        }
        return max;
    }
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-11 13:34
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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