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

public int maxProfit (int[] prices) {
        // write code here

        int max=0;
        int minp=prices[0];
        for (int i=0;i<prices.length;i++){

            if(minp>prices[i]){
                minp=prices[i];
            }else if(max<prices[i]-minp){
                max=prices[i]-minp;
            }

        }

        return max;
    }



全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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