原题目:https://leetcode-cn.com/problems/number-of-digit-one/
公式(LeetCode 题解):
代码:
class Solution {
public:
int countDigitOne(int n) {
int countr = 0;
for (long long i = 1; i <= n; i *= 10) {
long long divider = i * 10;
countr += (n / divider) * i + min(max(n % divider - i + 1, 0LL), i);
}
return countr;
}
};