Zepruv › Coding problems

Number of Digit One

Hard · Math, Dynamic Programming, Recursion

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 = 13
Output: 6

Example 2

Input: n = 0
Output: 0

Constraints

Starter code (python)

class Solution(object):
    def countDigitOne(self, n):
        """
        :type n: int
        :rtype: int
        """
        

Related problems

Previous: Power of Two · Next: Palindrome Linked List · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.