357 Count Numbers with Unique Digits
1. Question
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.
Example:
Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding[11,22,33,44,55,66,77,88,99]
)
2. Implementation
(1) Backtracking
(2) DP
3. Time & Space Complexity
Backtracking: 时间复杂度O(n!), 如果n > 10的话,时间复杂度为O(10!), 空间复杂度O(n)
DP: 时间复杂度O(n), 空间复杂度O(1)
Last updated