Fork me on GitHub

Lintcode 150.买卖股票的最佳时机 II

------------------------------------------------------------

 

卧槽竟然连题意都没看懂,百度了才明白题目在说啥....我好方啊....o(╯□╰)o

 

AC代码:

class Solution {
    /**
     * @param prices: Given an integer array
     * @return: Maximum profit
     */
    public int maxProfit(int[] prices) {
        int res=0;
        for(int i=1;i<prices.length;i++){
            int t=prices[i]-prices[i-1];
            if(t>0) res+=t;
        }
        return res;
    }
};

 

 

题目来源: http://www.lintcode.com/zh-cn/problem/best-time-to-buy-and-sell-stock-ii/#

posted @ 2017-01-01 22:13  CC11001100  阅读(130)  评论(0编辑  收藏  举报