5 lines C++ DP solution


  • 0
    S
    class Solution {
    public:
        int countNumbersWithUniqueDigits(int n) {
            int f=1;
            for(int i=1,tmp=9,N=min(n,10);i<= N;i++){   
                f += tmp;
                tmp *= 10-i;}
            return f;
        }
    };
    

Log in to reply
 

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