problem
從股票價位陣列中找出,可以最大化淨利
Solution
option 1
- 維護一個dp 紀錄歷史至今最低價位,在用當天股價減去至今最低點,並更新ret
1 | class Solution { |
option 2 - algo
1 | class Solution { |
option 3 - dp
1 | class Solution { |
option 4 - reduce dp
1 | class Solution { |
analysis
- option 1
- time complexity
O(n)
- speed complexity
O(n)
- time complexity
- option 2
- time complexity
O(n)
- space complexity
O(1)
- time complexity
- option 3
- time complexity
O(n)
- space complexity
O(n)
- time complexity
- option 4
- time complexity
O(n)
- space complexity
O(1)
- time complexity