```
class Solution {
public:
int findNthDigit(int n) {
int count = 1;
while (true) {
int tmp = count * pow(10, count - 1) * 9;
if (n - tmp <= 0) break;
n -= tmp;
count++;
}
int n_tmp = pow(10, count - 1) + ceil(1.0 * n / count) - 1;
int n_mod = n % count == 0 ? count : n % count;
return (n_tmp / (int)pow(10, count - n_mod)) % 10;
}
};
```