1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: int findNthDigit(int n) { long digit = 1, count = 9, start = 1; while(count < n) { n -= count; start *= 10; ++digit; count = 9 * digit * start; } int num = (n - 1) / digit + start; return to_string(num)[(n - 1) % digit] - '0'; } };
|