263. Ugly Number
Input: 6
Output: true
Explanation: 6 = 2 × 3Input: 8
Output: true
Explanation: 8 = 2 × 2 × 2Input: 14
Output: false
Explanation: 14 is not ugly since it includes another prime factor 7.# @param {Integer} num
# @return {Boolean}
def is_ugly(num)
return false if num == 0
while num % 2 == 0
num = num / 2
end
while num % 3 == 0
num = num / 3
end
while num % 5 == 0
num = num / 5
end
num == 1
endLast updated