#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param n int整型
# @return int整型
#
class Solution:
def findNthDigit(self , n: int) -> int:
# write code here
if n == 0:
return 0
digit = 1 #数字位数, 1, 2, 3, ...
start = 1 #起始值, 1, 10, 100
count = 9 #各个区间的总位数, 9, 9*2*10=180
while n > count: #1.求n所在的 数字位数区间 如第10位(1)对应数位数区间为2
n -= count
digit += 1
start *= 10
count = 9 * digit * start #计算不同区间位数的公式
#2.确定所求位数n对应的数字num
num = start + (n-1) // digit
#3.确定所求位数,确定num对应的位数
res = int(str(num)[n % digit-1])
return res