Short. Easy to understand Math solution. Java


  • 0
    O
    
        public int countNumbersWithUniqueDigits(int n) {
            if(n == 0) {
                return 1;
            }
            int uniq = 10, tmp;
            for(int i = 2; i <= n; i++) {
                tmp = 9;
                for(int j = 2; j <= i; j++) {
                    tmp *= 9-j+2;
                }
                uniq += tmp;
            }
            return uniq;
        }
    

Log in to reply
 

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