image.png

code

  1. class Solution {
  2. public boolean isUgly(int num) {
  3. if (num == 0) {
  4. return false;
  5. }
  6. while(num % 2 ==0) {
  7. num /= 2;
  8. }
  9. while(num % 3 == 0) {
  10. num /= 3;
  11. }
  12. while(num % 5 == 0) {
  13. num /= 5;
  14. }
  15. return num == 1;
  16. }
  17. }