1957

无聊蛋疼的1957写的低端博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[leetcode]Best Time to Buy and Sell Stock II

Posted on 2013-08-22 20:48  1957  阅读(137)  评论(0编辑  收藏  举报

感觉比I还水

能买卖多次...问最大收益...

class Solution {
public:
    int maxProfit(vector<int> &prices) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int ans = 0;
        for(int i = 1 ; i < prices.size() ; i++)
            if(prices[i] - prices[i-1] > 0) ans += prices[i] - prices[i-1];
        return ans;
    }
};