class Solution(object):

```
def findNthDigit(self, n):
"""
:type n: int
:rtype: int
"""
if n <= 0:
return 0;
if n <= 9:
return n;
nstr = str(n);
N = len(nstr) -1;
m = self.f(N);
while m > n:
N = N-1;
m = self.f(N);
N = N+2;
a = (n-m)/N;
b = (n-m)%N;
a = a + 10**(N-1);
if b ==0:
return (a-1)%10;
else:
return int(str(a)[b-1]);
def f(self, N):
# return the total number of digits for number with N+1 digits
return (10**(N+1)*(10*N+10-N-2)+1)/9;
```