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