当前位置:网站首页>Greedy interval problem (4)

Greedy interval problem (4)

2022-06-22 22:40:00 Douglas_ LT

A daily topic ing, Today is a day medium topic 122. Best Time to Buy and Sell Stock II

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

	return profit;
    }
};
原网站

版权声明
本文为[Douglas_ LT]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221745247233.html