LeetCode121。株式を売却するための最良の時間(JAVAの実現)

トピック:

コード:

class Solution {
    public int maxProfit(int[] prices) {
        int maxProfit=0;
        for(int i=0;i<prices.length-1;i++){
            for(int j=i+1;j<prices.length;j++){
                int profit=prices[j]-prices[i];
                if(profit>maxProfit){
                    maxProfit=profit;
                }
                
            }
        }
        

    return maxProfit;
    }
}

 

公開された31元の記事 ウォンの賞賛1 ビュー1253

おすすめ

転載: blog.csdn.net/qq_45824565/article/details/104593166