0263.cpp (207B)
1 class Solution { 2 public: 3 bool isUgly(int n) { 4 if (n <= 0) return false; 5 for (auto i : {2, 3, 5}) 6 while (n % i == 0) 7 n /= i; 8 9 return n == 1; 10 } 11 };