Description
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.
Examples
Input:
n = 13Output:
6Explanation:
Digit 1 appears in: 1, 10, 11, 12, 13. Count: 1+1+2+1+1 = 6.
Input:
n = 0Output:
0Explanation:
No positive integers ≤ 0.
Input:
n = 25Output:
9Explanation:
Digit 1 appears in: 1, 10, 11 (twice), 12, 13, 14, 15, 16, 17, 18, 19, 21. The total count of digit 1 across all numbers from 1 to 21 is 13.
Constraints
- •
0 ≤ n ≤ 10⁹