@rg070836rg
2015-11-27T00:44:50.000000Z
字数 277
阅读 1302
leetcode
贪心
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
class Solution {
public:
int maxProfit(vector<int>& prices) {
int n=prices.size();
int sum=0;//定义利润
for(int i=1;i<n;i++)
{
if(prices[i]-prices[i-1]>0)
sum+=prices[i]-prices[i-1];
}
return sum;
}
};