1 int maxProfit(int* prices, int pricesSize) { 2 int sum=0,i; 3 if(prices==NULL||pricesSize==1) 4 return 0; 5 for(i=1;i<pricesSize;i++) 6 { 7 if(prices[i]>prices[i-1]) 8 sum=prices[i]-prices[0]; 9 else 10 { 11 return sum+maxProfit(prices+i,pricesSize-i); 12 } 13 } 14 return prices[i-1]-prices[0]; 15 }
Best Time to Buy and Sell Stock II
原文:http://www.cnblogs.com/lou424/p/4638928.html