class Solution {
public int findNthDigit(int n) {
int len = 1;
int d = 0;
long a = 0;
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);
long x = n / len + s;
if(n % len == 0){
x--;
}
if(n == 0){
return 9;
}else{
d = n % len;
if(d == 0){
d = len;
}
while(len - d + 1 > 0){
a = x % 10;
x /= 10;
len--;
}
}
return (int)a;
}
}