Description
Given a set of digits and integer n, return the count of positive integers that can be formed using only given digits and are at most n.
Examples
Input:
digits = ["1","3","5","7"], n = 100Output:
20Explanation:
1-digit: 4 numbers (1,3,5,7). 2-digit: 16 combinations (4x4). Total: 4+16=20.
Input:
digits = ["2"], n = 23Output:
2Explanation:
With digit "2", the valid numbers are 2 and 22 (both ≤ 23). 222 exceeds the limit, so the answer is 2.
Input:
digits = ["1","2","3"], n = 15Output:
6Explanation:
Using digits ["1","2","3"], the valid numbers ≤ 15 are: 1, 2, 3, 11, 12, 13. Total: 6.
Constraints
- •
1 ≤ digits.length ≤ 9