Simple Java Solution


  • 0
        public int countNumbersWithUniqueDigits(int n) {
            int ret = 1, levelCnt = 9;
            // n = Math.min(n, 10); // Removed since the input n is always <= 10
            for (int k = 1; k <= n; k++) {
                ret += levelCnt;
                levelCnt *= (10-k);
            }
            
            return ret;
        }
    

Log in to reply
 

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