• 买卖股票的最佳时机 C++


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

  • 相关阅读:
    Stupid Tower Defense
    Lifting the Stone
    城市地平线
    BestCoder Sequence
    Miaomiao's Geometry
    Rating
    Turn the pokers
    Peter's Hobby
    HTTP关键词收集
    HTTP出现前的协议
  • 原文地址:https://www.cnblogs.com/1500802029xy/p/6523189.html
Copyright © 2020-2023  润新知