1. 程式人生 > >leetcode + 買賣股票,貪心

leetcode + 買賣股票,貪心

點選開啟連結
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int sum = 0;
        for(int i=1; i<prices.size(); i++){
            if(prices[i] > prices[i-1]){
                sum += prices[i] - prices[i-1];
            }
        }
        return sum;
    }
};