TLE Java recursion DFS


  • 1
    public class Solution {
        public boolean isUgly(int num) {
            return compareNum(num, 1);
        }
        
        public boolean compareNum(int num, int test) {
            if(num == test) return true;
            if(num < test) return false;
            return compareNum(num, test*2) || compareNum(num, test*3) || compareNum(num, test*5);
        }
    }
    

  • 0
    Z

    @tony.mu101999 said in TLE Java recursion DFS:

    public class Solution {
        public boolean isUgly(int num) {
            return compareNum(num, 1);
        }
        
        public boolean compareNum(int num, int test) {
            if(num == test) return true;
            if(num < test) return false;
            return compareNum(num, test*2) || compareNum(num, test*3) || compareNum(num, test*5);
        }
    }
    

Log in to reply
 

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