C++ Solution using dp


  • 0
    T

    note that: count[n] = count[n-1] + x_bits_nums

    int countNumbersWithUniqueDigits(int n) {
        int count = 1;
        for (int i = 1; i <= n; i++) {
    	    int x = 9;
    	    for (int j = 1; j < i; j++) {
    		    x *= (10 - j);
    	    }
    	    count += x;
        }
        return count;
    }

Log in to reply
 

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