python leetcode 400. Nth Digit

按着题目意思编程即可

class Solution(object):
    def findNthDigit(self, n):
        """
        :type n: int
        :rtype: int
        """
        count=1
        res=0
        while (res+count*9*10**(count-1))<=n:
             
            res+=count*9*10**(count-1)
            count+=1
        ds = n-res
        if ds==0:return 9
        
        yu=ds%count
        if yu==0:    
            dd=10**(count-1)+ds//count-1
            return int(str(dd)[-1])
        else:
            dd=10**(count-1)+ds//count
        
            return int(str(dd)[yu-1])

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/84592474