Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... 

Note:
n is positive and will fit within the range of a 32-bit signed integer (n < 231).


Example 1:

Input:
3

Output:
3



Example 2:

Input:
11

Output:
0

Explanation:
The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.

Difficulty: introductory

Starter code:

class Solution:
    def findNthDigit(self, n: int) -> int:
        

Solutions:
class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         i=count=9
         while count < n:
             i *= 10
             count += i * len(str(i))
         div, mod = divmod(n-(count-i*len(str(i))), len(str(i)))
         print(i, count, div, mod)
         target = (i//9-1) + div
         if mod == 0:
             print(target, int(str(target)[-1]))
             return int(str(target)[-1])
         else:
             return int(str(target+1)[mod-1])

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         digs = 1
         while n > 9*(10**(digs-1))*digs:
             n -= 9*(10**(digs-1))*digs
             digs += 1
         return int(str(int(10**(digs-1)+(n-1)/digs))[n%digs-1])

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         digitCount = 1
         totalNumbersWithDigitCount = 9*(10**(digitCount-1))*digitCount
         while n > totalNumbersWithDigitCount:
             n -= totalNumbersWithDigitCount
             digitCount += 1
             totalNumbersWithDigitCount = 9*(10**(digitCount-1))*digitCount
             
         baseNumber = 10**(digitCount-1) - 1
         targetNumber = baseNumber + math.ceil(n/digitCount)
         targetDigitIndex = (n%digitCount) - 1
         
         return int(str(targetNumber)[targetDigitIndex])

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         start=0;
         digit=0;
         while True:
             temp=9*10**digit;
             if temp*(digit+1)<n:
                 n-=temp*(digit+1);
                 start+=10**digit*9
                 digit+=1;
             else:break
         step=int(n/(digit+1))
         start+=step;
         n-=(digit+1)*step;
         if n==0:return start%10;
         start+=1;
         return (int(start/10**(digit+1-n)))%10

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         n -= 1
         for digits in range(1, 11):
             first = 10**(digits - 1)
             if n < 9 * first * digits:
                 return int(str(first + n/digits)[n%digits])
             n -= 9 * first * digits

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         # 1-9: 9, 10-99: 90, 100-999: 900, 1000-9999: 9000
         i, count = 1, 9
         total = 9
         while total < n:
             i += 1
             count *= 10
             total += i*count
         
         n -= total - i*count + 1
         return int(str(n//i+10**(i-1))[n%i])

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         n -= 1
         for digits in range(1, 11):
             first = 10**(digits - 1)
             if n < 9 * first * digits:
                 return int(str(first + n/digits)[n%digits])
             n -= 9 * first * digits

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         
    #    my fourth solution.........
         if n <= 0:
             return
         
         i = 0
         nbase = 0
         thres = 1*9
         if n <= thres:
             return n
         
         while 1:
             i += 1
             nbase += 9*10**(i-1)
             thres += (i+1)*9*10**i
             if n <= thres:
                 return int(str((n+i-(thres-(i+1)*9*10**i))//(i+1) + nbase)[(n+i-(thres-(i+1)*9*10**i))%(i+1)])
                            
                            
                            
                            
         """
    #    my third solution....beat 93%....
         if n <= 0:
             return
         
         nbase = 0
         thres = 1*9
         if n <= thres:
             return n
         
         nbase += 9*10**0
         thres += 2*9*10**1
         if n <= thres:
             return int(str((n+1-(thres-2*9*10**1))//2 + nbase)[(n+1-(thres-2*9*10**1))%2])
         
         nbase += 9*10**1
         thres += 3*9*10**2
         if n <= thres:
             return int(str((n+2-(thres-3*9*10**2))//3 + nbase)[(n+2-(thres-3*9*10**2))%3])
         
         nbase += 9*10**2
         thres += 4*9*10**3
         if n <= thres:
             return int(str((n+3-(thres-4*9*10**3))//4 + nbase)[(n+3-(thres-4*9*10**3))%4])
         
         nbase += 9*10**3
         thres += 5*9*10**4
         if n <= thres:
             return int(str((n+4-(thres-5*9*10**4))//5 + nbase)[(n+4-(thres-5*9*10**4))%5])
         
         nbase += 9*10**4
         thres += 6*9*10**5
         if n <= thres:
             return int(str((n+5-(thres-6*9*10**5))//6 + nbase)[(n+5-(thres-6*9*10**5))%6])
         
         nbase += 9*10**5
         thres += 7*9*10**6
         if n <= thres:
             return int(str((n+6-(thres-7*9*10**6))//7 + nbase)[(n+6-(thres-7*9*10**6))%7])
         
         nbase += 9*10**6
         thres += 8*9*10**7
         if n <= thres:
             return int(str((n+7-(thres-8*9*10**7))//8 + nbase)[(n+7-(thres-8*9*10**7))%8])
         
         nbase += 9*10**7
         thres += 9*9*10**8
         if n <= thres:
             return int(str((n+8-(thres-9*9*10**8))//9 + nbase)[(n+8-(thres-9*9*10**8))%9])
         """
                            
                            
         
         
         """
    #    my second solution........beat 96%....
         if n <= 0:
             return
         
         if n <= 1*9:
             return n
         
         if n <= 1*9+2*90:
             return int(str((n+1 - 1*9)//2 + 9)[(n+1 - 1*9)%2])
         
         if n <= 1*9+2*90+3*900:
             return int(str((n+2 - 1*9-2*90)//3 + 99)[(n+2 - 1*9-2*90)%3])
         
         if n <= 1*9+2*90+3*900+4*9000:
             return int(str((n+3 - 1*9-2*90-3*900)//4 + 999)[(n+3 - 1*9-2*90-3*900)%4])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000:
             return int(str((n+4 - 1*9-2*90-3*900-4*9000)//5 + 9999)[(n+4 - 1*9-2*90-3*900-4*9000)%5])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000:
             return int(str((n+5 - 1*9-2*90-3*900-4*9000-5*90000)//6 + 99999)[(n+5 - 1*9-2*90-3*900-4*9000-5*90000)%6])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000+7*9000000:
             return int(str((n+6 - 1*9-2*90-3*900-4*9000-5*90000-6*900000)//7 + 999999)[(n+6 - 1*9-2*90-3*900-4*9000-5*90000-6*900000)%7])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000+7*9000000+8*90000000:
             return int(str((n+7 - 1*9-2*90-3*900-4*9000-5*90000-6*900000-7*9000000)//8 + 9999999)[(n+7 - 1*9-2*90-3*900-4*9000-5*90000-6*900000-7*9000000)%8])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000+7*9000000+8*90000000+9*900000000:
             return int(str((n+8 - 1*9-2*90-3*900-4*9000-5*90000-6*900000-7*9000000-8*90000000)//9 + 99999999)[(n+8 - 1*9-2*90-3*900-4*9000-5*90000-6*900000-7*9000000-8*90000000)%9])
         """
         
         
 
         
         
         
         """
    #    my first solution...........beat 93%.....
         if n <= 0:
             return
         
         if n <= 1*9:
             return n
         
         if n <= 1*9+2*90:
             return int(str((n+1 - 1*9)//2 + 9)[n%2])
         
         if n <= 1*9+2*90+3*900:
             return int(str((n+2 - 1*9-2*90)//3 + 99)[n%3-1])
         
         if n <= 1*9+2*90+3*900+4*9000:
             return int(str((n+3 - 1*9-2*90-3*900)//4 + 999)[n%4-2])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000:
             return int(str((n+4 - 1*9-2*90-3*900-4*9000)//5 + 9999)[n%5])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000:
             return int(str((n+5 - 1*9-2*90-3*900-4*9000-5*90000)//6 + 99999)[n%6-4])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000+7*9000000:
             return int(str((n+6 - 1*9-2*90-3*900-4*9000-5*90000-6*900000)//7 + 999999)[n%7])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000+7*9000000+8*90000000:
             return int(str((n+7 - 1*9-2*90-3*900-4*9000-5*90000-6*900000-7*9000000)//8 + 9999999)[n%8-2])
         
         if n <= 1*9+2*90+3*900+4*9000+5*90000+6*900000+7*9000000+8*90000000+9*900000000:
             return int(str((n+8 - 1*9-2*90-3*900-4*9000-5*90000-6*900000-7*9000000-8*90000000)//9 + 99999999)[n%9-1])
         """


class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         multiple = math.floor(math.log10(n))
         subtract = sum([math.pow(10,i) for i in range(0, multiple)])
         boundary = multiple*math.pow(10,multiple)-subtract
         diff = n-boundary
 
         if(diff>0):
             x = (math.pow(10, multiple) - 1) + math.ceil(diff/(multiple+1))
             p = (diff-1)%(multiple+1)
         elif(diff<=0):
             x = math.pow(10,multiple)+ math.ceil(diff / (multiple))-1
             p = (diff-1)%(multiple)
 
         r = [ch for ch in str(x)][int(p)]
 
         
         return int(r)

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         n -= 1
         for digits in range(1, 11):
             first = 10**(digits - 1)
             if n < 9 * first * digits:
                 return int(str(first + n//digits)[n%digits])
             n -= 9 * first * digits

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         
         g = 1
         while True:
             g_len = (10 ** g - 10 ** (g - 1)) * g
             if n <= g_len:
                 break
                 
             n -= g_len
             g += 1
             
         idx = (n - 1) // g
         pos = (n - 1) % g
         
         num = 10 ** (g - 1) + idx
         return int(str(num)[pos])


class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         multiple = math.floor(math.log10(n))
         subtract = sum([math.pow(10,i) for i in range(0, multiple)])
         boundary = multiple*math.pow(10,multiple)-subtract
         diff = n-boundary
 
         if(diff>0):
             x = (math.pow(10, multiple) - 1) + math.ceil(diff/(multiple+1))
             p = (diff-1)%(multiple+1)
         elif(diff<=0):
             x = math.pow(10,multiple)+ math.ceil(diff / (multiple))-1
             p = (diff-1)%(multiple)
 
         r = [ch for ch in str(x)][int(p)]
 
         
         return int(r)

class Solution:
     def findNthDigit(self, n):
         """
         :type n: int
         :rtype: int
         """
         n_digit=1
         while n>(n_digit*9*(10**(n_digit-1))):
             n-=n_digit*9*(10**(n_digit-1))
             n_digit+=1
         n_pre=(n-1)//n_digit
         digit_position=(n-1)%n_digit+1
         num=10**(n_digit-1)+n_pre
         tmp=0
         num=(num%10**(n_digit-digit_position+1))//(10**(n_digit-digit_position))
         return num