bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 326. Power of Three

326. Power of Three

Leetcode Solutions

Approach: Integer Limitations

  1. Check if n is less than 1. If it is, return false because powers of three are positive numbers.
  2. Calculate 3^19 which is the largest power of three that fits in an integer.
  3. Check if 3^19 modulo n is 0. If it is, n is a divisor of 3^19 and thus a power of three.
  4. Return true if the modulo is 0, otherwise return false.
UML Thumbnail

Approach: Loop Iteration

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...