You are viewing a single comment's thread. Return to all comments →
Java O(n)
public static long stockmax(List<Integer> prices) { long maxProfit = 0; int maxFuturePrice = 0; for (int i = prices.size() - 1; i >= 0; i--) { if (prices.get(i) > maxFuturePrice) { maxFuturePrice = prices.get(i); } maxProfit += maxFuturePrice - prices.get(i); } return maxProfit; }
Seems like cookies are disabled on this browser, please enable them to open this website
Stock Maximize
You are viewing a single comment's thread. Return to all comments →
Java O(n)