Leetcode 263 Solution

This article provides solution to leetcode question 263 (ugly-number)

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

Solution

class Solution {
public:
    bool isUgly(int num) {
        if (num <= 0)
            return false;

        while (num != 1)
        {
            if (num % 2 == 0)
                num /= 2;
            else if (num % 3 == 0)
                num /= 3;
            else if (num % 5 == 0)
                num /= 5;
            else
                return false;
        }

        return true;
    }
};