Skip to content

Latest commit

 

History

History

ugly-number

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Ugly number

Problem link

Solutions

Solution.cpp

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

class Solution {
 public:
  bool isUgly(int n) {
    vector<int> primes{2, 3, 5};
    for (int p : primes)
      while (n and n % p == 0) n /= p;
    return n == 1;
  }
};

Tags