94% Running Time Faster, yet simple python solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport math\n\nFACT9 = math.factorial(9)\n\ndef getCountByNumber(n):\n    if n < 2:\n        return 0\n    return int(9*(10**(n-1)) - 9*(FACT9/math.factorial(9-n+1)))\n\nclass Solution:\n    def numDupDigitsAtMostN(self, n: int) -> int:\n        len_n = len(str(n))\n        list_n = list(str(n))\n        res = 0\n        for i in range(2,len_n):\n            res += getCountByNumber(i)\n\n        s = 1\n        for i in range(len_n-1, -1, -1):\n            if i > 0:\n                s += (int(list_n[i]) * (10**(len_n-i-1)))\n            else:\n                s += ((int(list_n[i])-1) * (10**(len_n-i-1)))\n        u = 1 if len(set(list_n)) == len_n else 0\n        for i in range(len_n-1, -1, -1):\n            if len(set(list_n[:i])) < i:\n                continue\n            else:\n                if i > 0:\n                    cur = int(list_n[i])\n                    for e in list_n[:i]:\n                        if int(e) < int(list_n[i]):\n                            cur -= 1\n                    tmp = 1\n                    for j in range(len_n-i-1):\n                        tmp *= (9-i-j)\n                    u += (cur * tmp)\n                else:\n                    cur = int(list_n[i])-1\n                    tmp = 1\n                    for j in range(len_n-i-1):\n                        tmp *= (9-i-j)\n                    u += (cur * tmp)\n        res += (s-u)\n        return res\n```
['Python3']