Try   HackMD

121. Best Time to Buy and Sell Stock


Optimal Space & Time Complexity
- Time complexity:
- Space 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/

  1. 直覺會覺得使用左右指針來做,left 找最小值,right 找最大值
  2. 更新的邏輯
    1. Fix left
      1. Right > left => update maxProfit
      2. Right < left => left = right
    2. Loop ends when right < prices.length

YC

SOL