# 数字 1 的个数

给定一个整数 n,计算所有小于等于 n 的非负整数中数字 1 出现的个数。

 

示例 1:

输入:n = 13
输出:6

示例 2:

输入:n = 0
输出:0

 

提示:

## template ```python class Solution: def countDigitOne(self, n: int) -> int: res, i = 0, 1 while i <= n: res += n // (i * 10) * i x = (n // i) % 10 res += i if x > 1 else (n % i + 1) * x i *= 10 return res ``` ## 答案 ```python ``` ## 选项 ### A ```python ``` ### B ```python ``` ### C ```python ```