TS 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```\nfunction numDupDigitsAtMostN(n: number): number {\n    const s = n.toString();\n    const dp = Array.from({length: s.length}, () => Array(1<<10).fill(-1));\n    const dfs = (i: number, mask: number, is_limit: boolean, leading0s: boolean): number => {\n        if (i === s.length) return leading0s? 0: 1;\n        if (!is_limit && !leading0s && dp[i][mask] !== -1) return dp[i][mask];\n        let sub = 0;\n        if (leading0s) sub = dfs(i+1, mask, false, true);\n        const low = leading0s? 1:0, high = is_limit? +s[i]: 9;\n        for (let d = low; d <= high; d+=1) {\n            if ((mask >> d & 1) === 0) {\n                sub += dfs(i+1, mask | (1<<d), is_limit && d === high, false);\n            }\n        }\n        if (!is_limit && !leading0s) dp[i][mask] = sub;\n        return sub;\n    };\n    return n - dfs(0, 0, true, true);\n}\n```
['TypeScript']