码迷,mamicode.com
首页 > 其他好文 > 详细

best-time-to-buy-and-sell-stock-ii

时间:2017-03-07 08:40:06      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:最大   turn   个数   logs   ++   div   ice   pre   统计   

//给定数组,统计各个数字的最大和。

class Solution {
public:
    int maxProfit(vector<int> &prices) {
        int res = 0;
        int n = prices.size();
        for (int i = 0; i < n - 1; ++i) {
            if (prices[i] < prices[i + 1]) {
                res += prices[i + 1] - prices[i];
            }
        }
        return res;
    }
};

 

best-time-to-buy-and-sell-stock-ii

标签:最大   turn   个数   logs   ++   div   ice   pre   统计   

原文地址:http://www.cnblogs.com/xiuxiu55/p/6512803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!