正确答案是B(1615)
因此,一共出现的次数为`205+210+200+1000 = 1615`。
代码实现如下。
//C++ class Solution { public: int countDigitOne(int n) { if(n<1){ return 0; } int count = 0; int base = 1; int round = n; int weight; while(round>0){ weight = round%10; round /= 10; count += round*base; if(weight == 1){ count += (n%base)+1; } else if(weight > 1){ count += base; } base *= 10; } return count; } };