首页 > 其他 > 详细

leetcode -- Best Time to Buy and Sell Stock II

时间:2014-05-30 02:45:42      阅读:384      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
class Solution {
public:
    int maxProfit(vector<int> &prices) {
        if(prices.size() == 0) return 0;
        vector<int> f(prices.size());
        f[0] = 0;
        for(int i = 1;i< prices.size();i++)
        {
            if(prices[i] > prices[i - 1])
               f[i] = f[i - 1] + prices[i] - prices[i - 1];
            else
               f[i] = f[i-1];
        }
        return f[prices.size() - 1];
    }
};
bubuko.com,布布扣

 

leetcode -- Best Time to Buy and Sell Stock II,布布扣,bubuko.com

leetcode -- Best Time to Buy and Sell Stock II

原文:http://www.cnblogs.com/berkeleysong/p/3757900.html

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