Skip to main content

326 - Power of Three

Details

KeyValue
Linkhttps://leetcode.com/problems/power-of-three/
LanguagePython 3
Runtime91 ms, faster than 87.36% of Python3 online submissions for Power of Three
Memory Usage13.9 MB, less than 16.98% of Python3 online submissions for Power of Three
Datastructuresint
AlgorithmsMath + Integer Limits
ComplexityTime: O(1) Memory: O(1)

Procedure

  1. ...

Code

class Solution:
def isPowerOfThree(self, n: int) -> bool:
# Can get 1162261467 using any of these:
# A) 3 ** 19
# B) pow(3, 32)
return n > 0 and 1162261467 % n == 0