leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0233.cpp (282B)
0 class Solution { 1 public: 2 int countDigitOne(int n) const { 3 int res = 0; 4 5 for (long long m = 1; m <= n; m *= 10) { 6 const int a = n / m, b = n % m; 7 res += (a + 8) / 10 * m + (a % 10 == 1) * (b + 1); 8 } 9 10 return res; 11 } 12 };