目录

三个月算法进阶--day72

找规律,稿纸上画一画

leetcode剑指offer第44题数字序列中某一位的数字

class Solution:
    def findNthDigit(self, n: int) -> int:
        count = 1
        tmp = 9
        while n > tmp * count:
            n -= tmp * count
            tmp = 9 * 10 ** count
            count += 1
        base = 10 ** (count - 1) + (n - 1) // count  ## n-1妙
        remainer = (n - 1) % count
        for _ in range(count - remainer):
            ans = base % 10
            base //= 10
        return ans