Leet121. 買賣股票的最佳時機(Best Time to Buy and Sell Stock)

https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/description/

public static int maxProfit(int[] prices) 
    {
        int maxEar=0;
        for(int i=prices.length-1;i>0;i--)
        {
            for(int j=i-1;j>=0;j--)
            {
               int temp=prices[i]-prices[j];
               if(temp>maxEar)
               {
                   maxEar=temp;
               }
            }
        }
        return maxEar;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章