本文共 637 字,大约阅读时间需要 2 分钟。

int maxProfit(int* prices, int pricesSize){       int i,min = INT_MAX,max = -1,profit = -1;    for(i=0;i        max)            {                   max = prices[i];            	if(max - min > profit)            		profit = max - min;            }        }    }    return profit;}       class Solution {   public:    int maxProfit(vector       & prices) {           int size = prices.size(),minbuy = prices[0],maxsold = 0;        for(const auto& num:prices)        {               maxsold = max(maxsold,num-minbuy);            minbuy = min(minbuy,num);        }        return maxsold;    }};    转载地址:http://shji.baihongyu.com/