diff --git a/2. Best Time to Buy and Sell Stock (Easy) b/2. Best Time to Buy and Sell Stock (Easy) new file mode 100644 index 000000000..4a4558383 --- /dev/null +++ b/2. Best Time to Buy and Sell Stock (Easy) @@ -0,0 +1,13 @@ +2. Best Time to Buy and Sell Stock (Easy) + +Problem: Max profit from one buy-sell transaction. + class Solution { + public int maxProfit(int[] prices) { + int min = prices[0], profit = 0; + for (int p : prices) { + min = Math.min(min, p); + profit = Math.max(profit, p - min); + } + return profit; + } +}