Easy python solution


  • 0
    Y
    class Solution(object):
        def findNthDigit(self, n):
            """
            :type n: int
            :rtype: int
            """
            width, num, digit, k = 1, 9, 0, 0
    
            while n > digit + width * num:
                digit += width * num
                k += num
                width += 1
                num *= 10
            
            n -= digit
            k += (n-1) // width + 1
            pos = (n-1) % width
            return int(str(k)[pos])
    

Log in to reply
 

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