Easy and elegant c++ solution.


  • 0
    class Solution {
    public:
      bool isUgly(int num) {
        int arr[3] = {2, 3, 5};
    
        if (num <= 0)
        {
          return false;
        }
        for (auto i : arr)
        {
          while (num % i == 0)
          {
    	num /= i;
          }
        }
        return num == 1;
      }
    };
    
    

Log in to reply
 

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