class Solution { public: //收益最大,并且没有手续费,可以无限交易,只要遇到升那么就赚一笔, int maxProfit(vector<int>& prices) { int ans=0; int n = prices.size(); for(int i=n-2; i>=0; --i){ if(prices[i] < prices[i+1]){ ans += (prices[i+1] - prices[i]); } } return ans; } };
class Solution { public: //收益最大,并且没有手续费,可以无限交易,只要遇到升那么就赚一笔, int maxProfit(vector<int>& prices) { int ans=0; int n = prices.size(); for(int i=n-2; i>=0; --i){ if(prices[i] < prices[i+1]){ ans += (prices[i+1] - prices[i]); } } return ans; } };