Swift | Recursive, *non* DP solution
The idea is to generate all numbers <= n that have unique digits and subtract the count from n.\n\nFinding the numbers with no repeated digits is very much liki
The idea is to generate all numbers <= n that have unique digits and subtract the count from n.\n\nFinding the numbers with no repeated digits is very much liking generating all the permutations of 0123456789, so it\'s a well known problem.\n\nBecause there are not that many such numbers (say less than a few million), this can be done on time with the problem constraints.\n\n\n\n# Code\n```\nclass Solution {\n    func numDupDigitsAtMostN(_ n: Int) -> Int {\n        func countUnique(_ prefix: Int, _ seen: inout [Bool], _ uniqueCount: inout Int) {\n            if prefix > n { return }\n            if prefix > 0 { uniqueCount += 1 }\n            for i in 0...9 where !seen[i] {\n                if prefix == 0 && i == 0 { continue }\n                seen[i] = true\n                countUnique(prefix * 10 + i, &seen, &uniqueCount)\n                seen[i] = false\n            }\n        }\n\n        var seen = Array(repeating: false, count: 10)\n        var uniqueCount = 0\n        countUnique(0, &seen, &uniqueCount)\n\n        return n - uniqueCount\n    }\n}\n```
['Swift']