题目描述
https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/
思路题解
class Solution:
def findNthDigit(self, n: int) -> int:
#n=193
digit, start, count = 1, 1, 9 #位数、左边界、数位数量
while n > count: # 1.确定范围
n -= count
start *= 10
digit += 1
count = 9 * start * digit #注意是9 9*1*1 9*10*2
print(n,digit,start,count)#4 3 100 2700
num = start + (n - 1) // digit # 2.确定是哪个数,n-1为了防止n=3时,数字为100(←)101,但是n//digit=n//3=3//3=1却为1不符合要求
print(start,num)
return int(str(num)[(n - 1) % digit]) # 3.确定是哪一位