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
Inputn = 13
Output6
From 0 to 13, the digit 1 appears in 1, 10, 11, 12, and 13 for a total of 6 times.
Example 2
Inputn = 0
Output0
There are no digit 1 occurrences in the only number 0.

Constraints

  • 0 <= n <= 10^9

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate