[leetcode]Best Time to Buy and Sell Stock II

感觉比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;
    }
};

 

你可能感兴趣的:(LeetCode)