44 数字序列中的某一位数字

2018-06-22  本文已影响0人  土味老猪
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))

        
上一篇下一篇

猜你喜欢

热点阅读