剑指Offer 63 股票的最大利润

Java版代码,leetcode地址

 1 class Solution {
 2     public int maxProfit(int[] prices) {
 3         int min_price = Integer.MAX_VALUE;
 4         int maxprofit = 0;
 5         int l = prices.length;
 6         for(int i = 0;i < l;i++){
 7             if(prices[i] < min_price){
 8                 min_price = prices[i];
 9             }else if(prices[i] - min_price > maxprofit){
10                 maxprofit = prices[i] - min_price;
11             }
12         }
13         return maxprofit;
14     }
15 }
原文地址:https://www.cnblogs.com/asenyang/p/15440615.html