int maxProfit(int* prices, int pricesLen ) { //if(prices == NULL || sizeof(prices) == 0) //return 0; int min = prices[0]; int max = -1; for(int i = 0; i < pricesLen; ++i){ //min用来维护历史的最小值 if(min > prices[i]) min = prices[i]; //max用来管理最大的利润 if(max < prices[i] - min) max = prices[i] - min; } return max; }