题目描述:
题解:
参考leetcode 400. 第 N 位数字 - 知乎
用n减去前面数字的位数,然后确定n对应的是第几个数字的第几个位置。
start记录起始位置,1,10,100...
digit记录每个数字的位数
count记录位数为digit的数字一共多少个字符=9*start*digit
class Solution:
def findNthDigit(self, n):
digit,start,count = 1,1,9
while n>count:
n-=count
start = start*10
digit = digit+1
count = 9*start*digit
num = start+(n-1)//digit
return int(str(num)[(n-1)%digit])



