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;
    }
};

posted @ 2019-12-08 12:06  尚修能的技术博客  阅读(92)  评论(0编辑  收藏  举报