zoukankan      html  css  js  c++  java
  • 【leetcode❤python】 400. Nth Digit

    #-*- coding: UTF-8 -*-
    class Solution(object):
        def findNthDigit(self, n):
            """
            :type n: int
            :rtype: int
            """
            res=n
            if n>9:
                index=1
                mul=9
                res=0
                while True:
                    tag=n-mul*index
                    
                    if tag>0:
                        n=tag;res+=mul
                        mul*=10
                        index+=1
                    else:index-=1;break
                
                print res,index,n
                div=n/(index+1)
                
                mod=n%(index+1)
                #应该是加1 而不是加mod
                if mod==0:
                    res=str(res+div)[-1]
                else:
                    res=str(res+div+1)[mod-1]
                return int(res)

            return res

    sol=Solution()
    print sol.findNthDigit(100000000)

  • 相关阅读:
    小程序云函数 Error: errCode: -404011 cloud function execution error
    Fiddler+雷电模拟器进行APP抓包
    Vue优化常用技巧
    sftp常用命令整理
    React生命周期学习整理
    git 提交跳过检查
    漂亮的代码系列
    关于我系列
    架构系列
    深度学习系列
  • 原文地址:https://www.cnblogs.com/kwangeline/p/6059565.html
Copyright © 2011-2022 走看看