leetcode122. 买卖股票的最佳时机 II

1、题目

https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/

2、题意

题解1:贪心

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

你可能感兴趣的:(leetcode)