Power of Three
Given an integer n, return true if it is a power of three. Otherwise, return false.
An integer n is a power of three, if there exists an integer x such that n == 3x.
Example 1:
1 | Input: n = 27 |
Example 2:
1 | Input: n = 0 |
Example 3:
1 | Input: n = -1 |
时间复杂度:O(logn)
空间复杂度:O(1)
1 | class Solution { |
最大约数法:
时间复杂度:O(1)
空间复杂度:O(1)
1 | class Solution { |