class Solution(object):
    def countDigitOne(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n <= 0:
            return 0

        count = 0
        base = 1
        num = n
        while num:
            remainder = num % 10
            num = num // 10
            count += (num * base)
            if remainder == 1:
                count += (n % base + 1)
            elif remainder > 1:
                count += base
            base *= 10

        return count

41e87d3269a12ec19d325b4946d225e07c2d0c29
<mask token>

class Solution(object):
    <mask token>

class Solution(object):

    def countDigitOne(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n <= 0:
            return 0
        count = 0
        base = 1
        num = n
        while num:
            remainder = num % 10
            num = num // 10
            count += num * base
            if remainder == 1:
                count += n % base + 1
            elif remainder > 1:
                count += base
            base *= 10
        return count

class Solution(object):
    def countDigitOne(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n <= 0:
            return 0

        count = 0
        base = 1
        num = n
        while num:
            remainder = num % 10
            num = num // 10
            count += (num * base)
            if remainder == 1:
                count += (n % base + 1)
            elif remainder > 1:
                count += base
            base *= 10

        return count
