1 int maxProfit(vector<int> &prices) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instance will be reused for each test case. 4 int i; 5 int res=0; 6 if(prices.size() <=1) 7 { 8 return 0; 9 } 10 for(i = 1;i<prices.size();++i) 11 { 12 if(prices[i] > prices[i-1]) 13 res+=(prices[i]-prices[i-1]); 14 } 15 return res; 16 }
=有些描述可能比我们想象的要复杂。