diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/121. Best Time to Buy and Sell Stock.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/121. Best Time to Buy and Sell Stock.java" new file mode 100644 index 00000000..8918570a --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/121. Best Time to Buy and Sell Stock.java" @@ -0,0 +1,13 @@ +class Solution { + public int maxProfit(int[] prices) { + int minPrice = Integer.MAX_VALUE; + int maxProfit = 0; + + for (int price : prices) { + if (price < minPrice) minPrice = price; + else if (price - minPrice > maxProfit) maxProfit = price - minPrice; + } + + return maxProfit; + } +} \ No newline at end of file