#233

Number of Digit One

master · 1830 · lc hard +32 · verified · 37.8% accepted · 1,820 likes · top 16%

play →

Description

Given an integer n, compute and return the total count of the digit 1 appearing across all non-negative integers from 0 to n inclusive.

Example 1:

Input: n = 13
Output: 6

Example 2:

Input: n = 0
Output: 0

Code

1
2
3