problem
solution
option 1 iterative and recursive
1 | class Solution { |
1 | class Solution { |
因為在[0,2^31-1]
之間最大的三次方數為3^19 = 1162261467
1 | return (n > 0 && 1162261467 % n == 0); |
option 2 - 換底公式
1 | class Solution { |
analysis
- time complexity
O(1)
- space complexity
O(1)