problem
solution
option 1 - brute force
1 | class Solution { |
option 2 - reduce
1 | class Solution { |
option 3 - prefix
1 | class Solution { |
option 4 - *math
analysis
- option 1
- time complexity
O(n^3)
- space complexity
O(1)
- time complexity
- option 2
- time complexity
O(n^2)
- space complexity
O(1)
- time complexity
- option 3 - prefix
- time complexity
O(n^2)
- space complexity
O(1)
- time complexity
- option 4 - math
- time complexity
O(n)
- space complexity
O(1)
- time complexity