All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0201_0300.s0263_ugly_number.Solution Maven / Gradle / Ivy

There is a newer version: 1.35
Show newest version
package g0201_0300.s0263_ugly_number;

// #Easy #Math #2022_07_05_Time_2_ms_(65.06%)_Space_41.3_MB_(46.18%)

public class Solution {
    public boolean isUgly(int n) {
        if (n == 1) {
            return true;
        } else if (n <= 0) {
            return false;
        }
        int[] factors = new int[] {2, 3, 5};
        for (int factor : factors) {
            while (n > 1 && n % factor == 0) {
                n /= factor;
            }
        }
        return n == 1;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy