400. Nth Digit

Question

CleanShot 2024-09-04 at 17.56.45@2x.png

Code

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

        digit = 1
        count = 9

        while n > digit * count:
            n -= digit * count
            digit += 1
            count *= 10

        n -= 1
        start = 10 ** (digit - 1)

        num = start + n // digit

        position = n % digit

        return int(str(num)[position])