Topic describes

Figures for 0123456789101112131415… To a sequence of characters. In this sequence, the fifth digit (counting from the subscript 0) is 5, the 13th digit is 1, the 19th digit is 4, and so on.

Write a function to find any number corresponding to the NTH digit.

Example 1: Input: n = 3 Output: 3

Example 2: Input: n = 11 Output: 0

Their thinking

Ideas from the K god solution

1. The arrangement of numbers can be one-digit, two-digit, three-digit, etc. The first step is to determine what number of digits n is in. To find the law, you can refer to the explanation of god K
2. For example, we determine by the first step that n is in the region of the three-digit order, we further determine which three-digit number it is in
3. The last step is to determine which of the three digits it is in

The sample code

``````def findNthDigit(self, n: int) - >int:
digit, start, count = 1.1.9
while n > count:  # 1
n -= count
start *= 10
digit += 1
count = 9 * start * digit
num = start + (n - 1) // digit  # 2.
return int(str(num)[(n - 1) % digit])  # 3.
Copy the code``````