Solve in Python:
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.

Example:


Input: 13
Output: 6 
Explanation: Digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
class Solution:
        def countDigitOne(self, n):
             ones, wei = 0,  1
             while wei <= n:
                 m = int(n / wei) % 10  # 求某位数字
 
                 if m > 1:
                     ones += (int(n / wei / 10) + 1) * wei
                 elif m == 1:
                     ones += (int(n / wei / 10)) * wei + (n % wei) + 1
                 else:
                     ones += (int(n / wei / 10)) * wei
                 wei *= 10
             return int(ones)