Java 2ms 1-liner just for fun


  • 0

    Nothing innovative going on here, just for fun. DP/recursive solution.

    
    public class Solution {
        public boolean isUgly(int num) {
            return (num <= 1) ? (num == 1) : (num % 2 == 0 && isUgly(num / 2)) 
            || (num % 3 == 0 && isUgly(num / 3)) 
            || (num % 5 == 0 && isUgly(num / 5));
        }
    }
    

Log in to reply
 

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