C++ DP O(1) O(1) solution


  • 0
    int countNumbersWithUniqueDigits(int n) {
        int dp=1;
        int tmp=9;
        for(int i=1;i<=n&&i<10;i++){
            dp+=tmp;
            tmp*=(10-i);
        }
        return dp;
    }

Log in to reply
 

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