1012. Numbers With Repeated Digits.cpp
Code\n\nclass Solution {\npublic:\n    int numDupDigitsAtMostN(int n) {\n        vector<int> V;\n        int n2 = n;\n        while(n2){\n            V.emplace_
**Code**\n```\nclass Solution {\npublic:\n    int numDupDigitsAtMostN(int n) {\n        vector<int> V;\n        int n2 = n;\n        while(n2){\n            V.emplace_back(n2%10);\n            n2/=10;\n        }\n        int len = V.size();       \n        int sum = 0;\n        for(int i = 0; i < len-1; i++){\n            sum += 9*A(9,i);\n        }       \n        vector<int> dig_visited(10,0);\n        for(int i = len-1; i >= 0; i--){\n            int dig = V[i];\n            int count = 0;\n            for(int j = 0; j < dig; j++){\n                if(dig_visited[j]){continue;}\n                count++;\n            }\n            if(i == len-1){count--;}\n            sum += count*A(10-(len-i), i);\n            if(dig_visited[dig]){break;}\n            if(i == 0 && dig_visited[dig] == 0){sum++;}\n            dig_visited[dig] = 1;\n        }        \n        return n - sum;\n    }    \n    int A(int num, int len){\n        int tmp = 1;\n        for(int i = 0; i < len; i++){tmp *= (num-i);}\n        return tmp;\n    }\n};\n```
['C']