【leetcode 简单】 第九十二题 第N个数字

在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 个数字。

注意:
是正数且在32为整形范围内 ( n < 231)。

示例 1:

输入:
3

输出:
3

示例 2:

输入:
11

输出:
0

说明:
第11个数字在序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... 里是0,它是10的一部分。


class Solution(object):
    def findNthDigit(self, n):
        """
        :type n: int
        :rtype: int
        http://bookshadow.com/weblog/2016/09/18/leetcode-nth-digit/
        """
        for i in range(9):
            d = 9 * 10 ** i
            if n<=d *(i+1):break
            n-=d*(i+1)
        n-=1
        return int(str(10**i + n / (i + 1))[n % (i + 1)])
原文地址:https://www.cnblogs.com/flashBoxer/p/9545526.html