Leetcode Problem 263. Ugly Number

263. Ugly Number

Leetcode Solutions

Key approach of the solution.

Algorithm

  1. Check if n is less than or equal to 0. If it is, return false.
  2. While n is divisible by 2, divide it by 2.
  3. While n is divisible by 3, divide it by 3.
  4. While n is divisible by 5, divide it by 5.
  5. If n is now 1, return true; otherwise, return false.
UML Thumbnail

Alternative approach using recursion

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...