Nth Digit

Problem Id: 400 Difficulty: Medium


Intuition

Solution


class Solution:
    def findNthDigit(self, n: int) -> int:
        digits = 1
        while n > 9 * (10 ** (digits - 1)) * digits:
            n -= 9 * (10 ** (digits - 1)) * digits
            digits += 1

        base = 10 ** (digits - 1)
        base += (n - 1) // digits
        # print(base)
        return int(str(base)[(n - 1) % digits])