Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.
Example 1
Input
n = 13Output
6From 0 to 13, the digit 1 appears in 1, 10, 11, 12, and 13 for a total of 6 times.
Example 2
Input
n = 0Output
0There are no digit 1 occurrences in the only number 0.
Constraints
- 0 <= n <= 10^9