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

leetcode 122 . Best Time to Buy and Sell Stock II

时间:2017-10-12 01:02:17      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:cpp   out   sel   time   solution   end   ice   ++   turn   

class Solution
{
public:

        int maxProfit(vector<int>& prices)
        {
            int local=0,golal = 0;
            for (int i=0; i<prices.size()-1; i++)
            {
                local = max(local + (prices[i+1] - prices[i]), 0);
                golal = max(golal,local);
            }
            cout<<golal<<endl;
            return golal;
        }

};

  

leetcode 122 . Best Time to Buy and Sell Stock II

标签:cpp   out   sel   time   solution   end   ice   ++   turn   

原文地址:http://www.cnblogs.com/sxy-798013203/p/7653564.html

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