class Solution():
def digitcount(self,n):
count = 9
digit = 1
numsum = 9
pre = 0
while n > numsum:
count = count*10
digit += 1
pre = numsum
numsum = count*digit +numsum
num = 10**(digit-1) + int((n-pre-1)/digit)
index = n - pre -1- (num - 10**(digit-1))*digit
return str(num)[index]
s = Solution()
print(s.digitcount(1001))
网友评论