1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| class Solution {
public int findNthDigit(int n) { int len = 1; while (len * 9 * Math.pow(10, len - 1) < n) { n -= len * 9 * Math.pow(10, len - 1); ++len; } long s = (long) Math.pow(10, len - 1); s += n / len - 1; n -= len * (n / len); return n == 0 ? (int) (s % 10) : (int) ((s + 1) / Math.pow(10, len - n) % 10); } }
|