有利可图就交易,反正不限次数~
-
class Solution {
-
public:
-
int maxProfit(vector<int> &prices) {
-
if(prices.size()<2) return 0;
-
int max=0;
-
int j=0;
-
while(j<prices.size()-1)
-
{
-
while(j<prices.size()-1&&prices[j]>=prices[j+1]) j++;
-
int pos=j;
-
while(j<prices.size()-1&&prices[j]<prices[j+1]) j++;
-
max+=(prices[j]-prices[pos]);
-
}
-
return max;
-
}
-
};