4ms Solution in C++


  • 5
    C
    class Solution {
    public:
        bool isUgly(int num) {
            if(num < 1)
                return false;
            
            for(int i = 2; i <= 5; i++)
            {
                while(num%i == 0)
                    num /= i;
            }
            
            if(num != 1)
                return false;
            return true;
        }
    };

  • 0
    S
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.