Simple Approach using digit DP
Code\n\nclass Solution {\npublic:\n    int dp[12][1<<10][2][2];\n    int func(string &num, int n, int vis, bool tight, bool zer){\n        if(n==0){\n          
# Code\n```\nclass Solution {\npublic:\n    int dp[12][1<<10][2][2];\n    int func(string &num, int n, int vis, bool tight, bool zer){\n        if(n==0){\n            return 1;\n        }\n        if(dp[n][vis][tight][zer]!=-1) return dp[n][vis][tight][zer];\n        int ans = 0;\n        int ub = tight ? (num[num.length()-n]-\'0\') : 9;\n        for(int dig = 0; dig <= ub; dig++){\n            if(zer==1 && dig==0){\n                ans+=func(num,n-1,vis,tight&(dig==ub),zer);\n            }\n            else if((vis&(1<<dig))==0){\n                ans+=func(num,n-1,(vis|(1<<dig)),tight&(dig==ub),zer&0);\n            }\n        }\n        return dp[n][vis][tight][zer] = ans;\n    }\n    int numDupDigitsAtMostN(int n) {\n        string s = to_string(n);\n        int len = s.size();\n        memset(dp,-1,sizeof(dp));\n        int ans = func(s,len,0,1,1);\n        return n+1-ans;\n    }\n};\n```
['C++']