• 38.7%

https://leetcode.com/problems/ugly-number/#/description

Write a program to check whether a given number is an ugly number.

Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.

Note that 1 is typically treated as an ugly number.

Credits:

num%2 num&1 num/2 num>>1 除以2的时候，尽量用位运算代替，效率较高

c / c++

8ms, 5.25%, May.2nd, 2016

https://leetcode.com/discuss/55542/4ms-short-c-solution

8ms, 5.25%, May.2nd, 2016

https://leetcode.com/discuss/52703/2-4-lines-every-language

#### python

https://discuss.leetcode.com/topic/27421/my-python-solution

Mine Solution:

64ms, 22.53%, May.2nd, 2016

Solution 1:

68ms, 14.68%, May.2nd, 2016

https://leetcode.com/discuss/52703/2-4-lines-every-language

Solution 2:

68ms, 14.68%, May.2nd, 2016

https://leetcode.com/discuss/97377/python-1-line-solution

Solution 3:

80ms, 4.65%, May.2nd, 2016

https://leetcode.com/discuss/64640/my-python-solution

#### java

https://discuss.leetcode.com/topic/21873/simple-java-solution-with-explanation

idea:

(1) basic cases: <= 0 and == 1

(2) other cases: since the number can contain the factors of 2, 3, 5, I just remove those factors. So now, I have a number without any factors of 2, 3, 5.

(3) after the removing, the number (new number) can contain a) the factor that is prime and meanwhile it is >= 7, or b) the factor that is not the prime and the factor is not comprised of 2, 3 or 5. In both cases, it is false (not ugly number).

For example, new number can be 11, 23 –> not ugly number (case a)). new number also can be 49, 121 –> not ugly number (case b))

https://discuss.leetcode.com/topic/33389/java-solution-greatest-divide-by-2-3-5

clean solution to greatest divide the num using 2, 3, and 5.

my code: