Given a positive integer n, count how many integers in the range [1, n] have all digits distinct. Pattern focus: Digit DP. Build numbers from left to right while tracking which digits have already appeared.
n = upper bound
count of integers in [1, n] with all distinct digits
Example 1:
Input:
n = 20
Output:
19
Explanation:
All numbers from 1 to 20 are special except 11.
Example 2:
Input:
n = 100
Output:
90
Explanation:
There are 90 special integers from 1 to 100.
Example 3:
Input:
n = 135
Output:
110
Explanation:
Numbers with repeated digits are excluded while counting up to 135.