首页 > 其他 > 详细

122. Best Time to Buy and Sell Stock II

时间:2016-05-22 00:42:15      阅读:238      评论:0      收藏:0      [点我收藏+]
    /*
     * 122. Best Time to Buy and Sell Stock II
     * 第二题,可以进行无限次,所以只要大于0的都加上
     */
    public int maxProfit2(int[] prices) {
        if (prices == null || prices.length == 0 || prices.length == 1)
            return 0;
        int res = 0;
        int low = prices[0];
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] > low) {
                res = res + prices[i] - low;
            }
            low = prices[i];
        }
        return res;
    }

 

122. Best Time to Buy and Sell Stock II

原文:http://www.cnblogs.com/zmyvszk/p/5515889.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!