package leetcode;

/**
 * https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
 */
public class Problem121 {
    public int maxProfit(int[] prices) {
        int[] max = new int[prices.length];
        int m = 0;
        for (int i = prices.length - 1; i >= 0; i--) {
            max[i] = Math.max(m, prices[i]);
            m = max[i];
        }
        int profit = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            int buy = prices[i];
            int sell = max[i + 1];
            profit = Math.max(profit, sell - buy);
        }
        return profit;
    }
}

@@ -170,16 +170,22 @@
 nt%5B%5D max
+Prices
  = new i
@@ -216,16 +216,23 @@
    int m
+axPrice
  = 0;%0A  
@@ -299,19 +299,21 @@
      max
-%5Bi%5D
+Price
  = Math.
@@ -317,16 +317,23 @@
 th.max(m
+axPrice
 , prices
@@ -355,17 +355,30 @@
    m
+axPrices%5Bi%5D
  = max
-%5Bi%5D
+Price
 ;%0A  
@@ -397,22 +397,22 @@
     int 
-profit
+answer
  = 0;%0A  
@@ -479,112 +479,62 @@
     
-int buy = prices%5Bi%5D;%0A            int sell = max%5Bi + 1%5D;%0A            profit = Math.max(profit, sell - buy
+answer = Math.max(answer, maxPrices%5Bi + 1%5D - prices%5Bi%5D
 );%0A 
@@ -561,14 +561,14 @@
 urn 
-profit
+answer
 ;%0A  

Update problem 121