python implementation


  • 0
    X
    class Solution(object):
        def findNthDigit(self, n):
            """
            :type n: int
            :rtype: int
            """
            s = 0
            i = 0
            while s<=n:
                i += 1
                s += i*9*(10**(i-1))
            s1 = s - i*9*(10**(i-1))
            d = n - s1
            x = d//i
            y = d%i
            if y == 0:
                n1 = x+10**(i-1)-1
                ss = str(n1)
                n2 = int(ss[len(ss)-1])
            else:
                n1 = x+10**(i-1)
                ss = str(n1)
                n2 = int(ss[y-1])
            return n2
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.