#-*- 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)

【leetcode❤python】 400. Nth Digit的更多相关文章

  1. 【LeetCode】400. Nth Digit 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  3. 【leetcode❤python】 19. Remove Nth Node From End of List

    #-*- coding: UTF-8 -*-#双指针思想,两个指针相隔n-1,每次两个指针向后一步,当后面一个指针没有后继了,前面一个指针的后继就是要删除的节点# Definition for sin ...

  4. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  5. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  6. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  7. 【LeetCode OJ】Remove Nth Node From End of List

    题目:Given a linked list, remove the nth node from the end of list and return its head. For example: G ...

  8. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

  9. 【leetcode❤python】 168. Excel Sheet Column Title

    class Solution(object):    def convertToTitle(self, n):        """        :type n: in ...

随机推荐

  1. 关于Java擦除特性

    package thinkingInJava; /* * 模拟擦除 */ public class SimpleHolder { private Object obj ; public void se ...

  2. Empire C:Basic 3

    首先我们定义一个表示年龄的指针: int* page: 这就是定义了一个指针,和定义普通变量就多了一个*符号而已. 为什么变量名用了p开头,这里引用了英文pointer(指向),表示它是一个指针,而非 ...

  3. 关于怎样解决eclipse打开时出现的Failed to load the JNIshared library亲测有效

    之前一直可以正常使用eclipse但是当我装了Oracle后打开后就出现了Failed to load the JNIshared library(下面还出现了一个jvm.dll的文件路径),当时就蒙 ...

  4. Xcode离线安装帮助文档

    Xcode离线安装帮助文档   1.在线查看帮助文件:Xcode下查看帮助文件,菜单Help-Developer Documentation在右上角搜索框中即可检索,但速度很慢,在线查看. 2.下载帮 ...

  5. RadioButton Control

    Horizontal Radiobuttons Column2 is DataGridViewTextBoxCell Horizontal Custom Radiobuttons => usin ...

  6. 正则基础之——捕获组(capture group)

    1        概述 1.1     什么是捕获组 捕获组就是把正则表达式中子表达式匹配的内容,保存到内存中以数字编号或显式命名的组里,方便后面引用.当然,这种引用既可以是在正则表达式内部,也可以是 ...

  7. win7 安装 memcached

    1. 下载 memcached-win32-1.4.4-14.zip,里面包含6个文件,将解压后的文件夹随便放在什么位置.如果需要win64版,下载 memcached-win64-1.4.4-14. ...

  8. jQuery源代码阅读之二——jQuery静态属性和方法

    一.jQuery.extend/jQuery.fn.extend //可接受的参数类型如下:jQuery.extend([deep],target,object1,[objectN]) jQuery. ...

  9. cocos2dx 3.x(动态改变精灵的背景图片)

    //更换精灵CCSprite的图片有两种方式. //直接通过图片更换 //使用setTexture(CCTexture2D*)函数,可以重新设置精灵类的纹理图片. // auto bg = Sprit ...

  10. 【转】Web性能压力测试工具之ApacheBench(ab)详解

    PS:网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个自带的,名为ab的程序,可以对Apache或其它类型的服务器进行网 ...