买卖股票的最佳时机
class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
int length=prices.size();
if(length<2)
return 0;
int profit=0;
int temp=prices[0];
for(int i=1;i<length;i++)
{
int profit0=prices[i]-temp;
if(profit0>profit)
{
profit=profit0;
}
if(temp>prices[i])
{
temp=prices[i];
}
}
return profit;
}
};