Javascript using DP and combination beats 95%


  • 0
    E
    var countNumbersWithUniqueDigits = function(n) {
        if(n === 0){
            return 1;
        }
        if(n === 1){
            return 10;
        }
        if(n > 10){
            return countNumbersWithUniqueDigits(10);
        }
        return countNumbersWithUniqueDigits(n - 1) + 9 * CombinationBasedNine(10 - n);
    };
    
    function CombinationBasedNine(n){
        var result = 9;
        while(n < 8){
            result *= (n + 1);
            n++;
        }
        return result;
    }
    

Log in to reply
 

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