Solution
C++ []\nclass Solution {\npublic:\n    int numDupDigitsAtMostN(int n) {\n        vector<int> digits{};\n        int temp = n + 1;\n        while (temp > 0) {\n 
```C++ []\nclass Solution {\npublic:\n    int numDupDigitsAtMostN(int n) {\n        vector<int> digits{};\n        int temp = n + 1;\n        while (temp > 0) {\n            digits.emplace_back(temp % 10);\n            temp /= 10;\n        }\n        int result = 0;\n        int len = digits.size();\n        int curr = 9;\n        for (int i = 0; i < len - 1; i++) {\n            result += curr;\n            curr *= 9 - i;\n        }\n        curr /= 9;\n        vector<bool> seen(10, false);\n        for (int i = 0; i < len; i++) {\n            int d = digits[len - i - 1];\n\n            for (int j = i == 0 ? 1 : 0; j < d; j++) if (!seen[j]) result += curr;\n            curr /= 9 - i;\n\n            if (seen[d]) break;\n            seen[d] = true;\n        }\n        return n - result;\n    }\n};\n```\n\n```Python3 []\nfrom math import perm\n\nclass Solution:\n    def numDupDigitsAtMostN(self, n: int) -> int:\n        digits = list(map(int, str(n + 1)))\n        nl = len(digits)\n        res = sum(9 * perm(9, i) for i in range(nl - 1))\n        s = set()\n        for i, x in enumerate(digits):\n            for y in range(i == 0, x):\n                if y not in s:\n                    res += perm(9 - i, nl - i - 1)\n            if x in s:\n                break\n            s.add(x)\n        return n - res\n```\n\n```Java []\nclass Solution {\n    public int numDupDigitsAtMostN(int N) {\n        ArrayList<Integer> L = new ArrayList<Integer>();\n        for (int x = N + 1; x > 0; x /= 10)\n            L.add(0, x % 10);\n\n        int res = 0, n = L.size();\n        for (int i = 1; i < n; ++i)\n            res += 9 * A(9, i - 1);\n\n        HashSet<Integer> seen = new HashSet<>();\n        for (int i = 0; i < n; ++i) {\n            for (int j = i > 0 ? 0 : 1; j < L.get(i); ++j)\n                if (!seen.contains(j))\n                    res += A(9 - i, n - i - 1);\n            if (seen.contains(L.get(i))) break;\n            seen.add(L.get(i));\n        }\n        return N - res;\n    }\n    public int A(int m, int n) {\n        return n == 0 ? 1 : A(m, n - 1) * (m - n + 1);\n    }\n}\n```
['C++', 'Java', 'Python3']