首页 > 其他 > 详细

121. Best Time to Buy and Sell Stock

时间:2019-12-08 13:52:51      阅读:65      评论:0      收藏:0      [点我收藏+]
  • 题目思路

  • 实现代码
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;
    }
};

技术分享图片

121. Best Time to Buy and Sell Stock

原文:https://www.cnblogs.com/Manual-Linux/p/12005209.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!