121. Best Time to Buy and Sell Stock
-
题目思路
-
实现代码
class Solution
{
public:
int maxProfit(vector<int>& prices)
{
int count = prices.size();
int profit = 0;
int tempprofit = 0;
for(int i = 0;i < count;i++)
{
for(int j = i + 1;j < count;j++)
{
tempprofit = prices[j] - prices[i];
if(tempprofit > profit)
{
profit = tempprofit;
}
}
}
return profit;
}
};