From a55bbbacf8331ed9b68dc80af28d0c84dc850b80 Mon Sep 17 00:00:00 2001 From: Rajesh Kapa Date: Mon, 9 Aug 2021 11:40:15 -0500 Subject: [PATCH] Update 121_Best_Time_to_Buy_and_Sell_Stock.java Reduces runtime , as we don't need to check min again --- Arrays/121_Best_Time_to_Buy_and_Sell_Stock.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Arrays/121_Best_Time_to_Buy_and_Sell_Stock.java b/Arrays/121_Best_Time_to_Buy_and_Sell_Stock.java index 8728a6b8..7815aec8 100644 --- a/Arrays/121_Best_Time_to_Buy_and_Sell_Stock.java +++ b/Arrays/121_Best_Time_to_Buy_and_Sell_Stock.java @@ -8,9 +8,8 @@ public int maxProfit(int[] prices) { for (int i = 1; i < prices.length; i++) { if (prices[i] < minPrices) { - minPrices = Math.min(minPrices, prices[i]); + minPrices = prices[i]; } - profit = Math.max(profit, prices[i] - minPrices); }