买卖股票的最佳时机

class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
int max=0;
int maxprices=0;
int lr=0;
for(int i=0;i<prices.size();i++)
{
maxprices=0;
for(int j=i+1;j<prices.size();j++)
{
if(maxprices<prices[j])
maxprices=prices[j];
}
lr=maxprices-prices[i];
if(max<lr)
max=lr;
}
return max;
}
};

posted @ 2017-03-08 20:22  DanielFour  阅读(94)  评论(0编辑  收藏  举报