classSolution { public: intcountDigitOne(int n){ int res = 0; ll base = 1; int rebuild = 0; while(n > 0) { int r = n % 10; n /= 10; rebuild += r*base; if (r == 0) { res += n*base; } elseif(r==1) { res += n*base+(rebuild-base+1); } else { res += (n+1)*base; } base *= 10; } return res; } };
Comments
shortname
for Disqus. Please set it in_config.yml
.