Skip to main content

🟡 剑指 Offer 44. 数字序列中某一位的数字

LeetCode 提示

题目难度 中等

原题链接 🔗 leetcode

题解 1.py#

class Solution:    def findNthDigit(self, n: int) -> int:        if n <= 9:            return n        n -= 10        length = 2        lengthTotal = 90        lengthStart = 10        while True:            if n <= lengthTotal*length:                theNum = n//length + lengthStart                return int(str(theNum)[n%length])            n -= lengthTotal*length            length += 1            lengthTotal *= 10            lengthStart *= 10