leetcode 122 . Best Time to Buy and Sell Stock II

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;
        }

};

  

posted @ 2017-10-11 23:58  799  阅读(113)  评论(0编辑  收藏  举报