121. Best Time to Buy and Sell Stock
Optimal Space & Time Complexity
Solutions
東
Hao
YC
SOL
Supplement / Discussion
東
Hao
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/solutions/1735550/python-javascript-easy-solution-with-very-clear-explanation/
- 直覺會覺得使用左右指針來做,left 找最小值,right 找最大值
- 更新的邏輯
- Fix left
- Right > left => update maxProfit
- Right < left => left = right
- Loop ends when right < prices.length
YC
SOL