problem
返回陣列,其元素為其餘元素相乘
Solution
維護兩個dp,一個從左往右累乘,另一個由右往左累乘
option 1
1 | class Solution { |
1 | class Solution { |
option 2 - reduce
1 | class Solution { |
analysis
- option 1
- time complexity
O(n)
- speed complexity
O(n)
- time complexity
- option 2
- time complexity
O(n)
- speed complexity
O(1)
- time complexity