思路:
一位数:9 * 1 * 1
两位数:9 * 10 * 2
三位数:9 * 100 * 3
四位数:9 * 1000 * 4
……
直到n小于对应位数的数字总和为止
然后把多出来是数字除以位数即可
class Solution:
def findNthDigit(self, n: int) -> int:
l = 1
w = 1
num = 9
while n > num:
n = n - num
w = w * 10
l = l + 1
num = 9 * w * l
x = n % l
y = n // l + w - 1
if x == 0:
ans = y % 10
else:
y = y + 1
for i in range(x):
ans = y // w
y = y % w
w = w // 10
return ans