Search topics...
All Problems
Was this helpful?
EasymathExpected: O(log n) time, O(1) space

Problem

Given an integer, determine whether it is an ugly number (prime factors limited to 2, 3, and 5).

Example 1:

Input: n = 6
Output: true
Explanation: 6 = 2 x 3

Example 2:

Input: n = 1
Output: true
Explanation: 1 has no prime factors.

Example 3:

Input: n = 14
Output: false
Explanation: 14 = 2 x 7, and 7 is not in {2, 3, 5}.
Reference solution unlocks after your first submission
Loading...