Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
An ugly number is a positive integer whose prime factors are limited to 2
, 3
, and 5
.
Given an integer n
, return true
if n
is an ugly number.
Example 1:
Input: n = 6
Output: true
Explanation: 6 = 2 × 3
Example 2:
Input: n = 1
Output: true
Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
Example 3:
Input: n = 14
Output: false
Explanation: 14 is not ugly since it includes the prime factor 7.
Constraints:
-231 <= n <= 231 - 1
for (int i=2; i<6 && num; i++)
while (num % i == 0)
num /= i;
return num == 1;
for p in 2, 3, 5:
while num % p == 0 < num:
num /= p
return num == 1
for (int i=2; i<6 && num>0; i++)
while (num % i == 0)
num /= i;
return num == 1;
In our experience, we suggest you solve this Ugly Number LeetCode Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Ugly Number LeetCode Solution
I hope this Ugly Number LeetCode Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>