Numbers With Repeated Digits
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```\n/**\n * @param {number} n\n * @return {number}\n */\nvar numDupDigitsAtMostN = function(n) {\n    const digits = String(n).split(\'\').map(Number);\n    const len = digits.length;\n    \n    const dp = Array.from({ length: len }, () => Array(1 << 10).fill(-1));\n    \n    const countUnique = (pos, mask, isTight, hasLeadingZero) => {\n        if (pos === len) return hasLeadingZero ? 0 : 1;\n        if (!isTight && dp[pos][mask] !== -1) return dp[pos][mask];\n        \n        let limit = isTight ? digits[pos] : 9;\n        let result = 0;\n        \n        for (let digit = 0; digit <= limit; digit++) {\n            if (hasLeadingZero && digit === 0) {\n                result += countUnique(pos + 1, mask, isTight && (digit === limit), true);\n            } else if ((mask & (1 << digit)) === 0) {\n                result += countUnique(pos + 1, mask | (1 << digit), isTight && (digit === limit), false);\n            }\n        }\n        \n        if (!isTight) dp[pos][mask] = result;\n        return result;\n    };\n    \n    const totalUnique = countUnique(0, 0, true, true);\n    \n    return n - totalUnique;\n};\n```
['JavaScript']