Backtracking with C++ in a few lines
\nclass Solution {\npublic:\n    int uniqueDigits = 0;\n    int numDupDigitsAtMostN(int N) {\n        backtrack(0,0, N);\n        return N - uniqueDigits + 1; /
```\nclass Solution {\npublic:\n    int uniqueDigits = 0;\n    int numDupDigitsAtMostN(int N) {\n        backtrack(0,0, N);\n        return N - uniqueDigits + 1; // +1 as 0 is counted\n    }\n    \n    void backtrack(long cur, int bitmask, int& N){\n        if(cur > N) return;\n        else uniqueDigits++;\n        \n        for(int digit=0; digit<10; digit++){\n            if(bitmask == 0 && digit == 0) continue;\n            if((bitmask & (1<<digit)) > 0) continue; // has repeat digits\n            backtrack(cur*10 + digit, bitmask | (1<<digit), N);\n        }\n    }\n};\n```
[]