My simple c++ math solution, nothing fancy


  • 2
    K
    class Solution {
    public:
    int countNumbersWithUniqueDigits(int n) {
        if(n==0)return 1;
        if(n==1)return 10;
        if(n==2)return 91;
        
        int base=81, count=91;
        for(int i=3; i <=min(10,n); i++){
            base=base * (10-i+1);
            count+=base;
        }
        return count;
    }
    

    };


Log in to reply
 

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