C++ Solution || Digit DP || Clean and Concise || Bitmask
Code\n\nclass Solution {\npublic:\n\n    int dp[10][2][1025][2]; //2^10 = 1024 for bitmask\n\n    int count(int idx,bool tight,int bitmask,bool isrepeated,strin
# Code\n```\nclass Solution {\npublic:\n\n    int dp[10][2][1025][2]; //2^10 = 1024 for bitmask\n\n    int count(int idx,bool tight,int bitmask,bool isrepeated,string& num){\n        if(idx==num.size()){\n            return (isrepeated&&bitmask)?1:0;\n        }\n        if(dp[idx][tight][bitmask][isrepeated]!=-1) return dp[idx][tight][bitmask][isrepeated];\n        int lo = 0;\n        int hi = tight?(num[idx]-\'0\'):9;\n        int cnt = 0;\n        if(!bitmask){\n            cnt += count(idx+1,false,bitmask,isrepeated,num);\n        }\n        for(int i = lo;i<=hi;i++){\n            if(!bitmask && i==0) continue;\n            int repeated = bitmask & (1<<i);\n            if(repeated){\n                cnt += count(idx+1,tight&&(i==hi),bitmask,true,num);\n            }\n            else{\n                cnt += count(idx+1,tight&&(i==hi),bitmask|(1<<i),isrepeated,num);\n            }\n        }\n        return dp[idx][tight][bitmask][isrepeated] = cnt;\n    }\n\n    int numDupDigitsAtMostN(int n) {\n        memset(dp,-1,sizeof(dp));\n        string num = to_string(n);\n        return count(0,true,0,false,num);\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Bitmask', 'C++']