#-*- 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. Maven详解之聚合与继承

    说到聚合与继承我们都很熟悉,maven同样也具备这样的设计原则,下面我们来看一下Maven的pom如何进行聚合与继承的配置实现. 一.为什么要聚合? 随着技术的飞速发展和各类用户对软件的要求越来越高, ...

  2. 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能

    我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...

  3. 一道打印M的面试题

    public class Demo { /** * 平面图形题(二维数组) */ public static void main(String[] args) { int num = 25; int ...

  4. Ceph与OpenStack的Nova相结合

    https://ervikrant06.wordpress.com/2015/10/24/how-to-configure-ceph-as-nova-compute-backend/ 在Ceph的ad ...

  5. Java Web项目_部门内部留言板

    t_user用户登录数据表 用户登录界面 JSP开发 通过post请求提交给Servlet处理 Servlet处理连接数据库的处理 登陆成功服务器跳转RequestDispatcher到main.js ...

  6. js判断移动终端url跳转

    CODE <script> //判断终端url跳转 function sp_isMobile() { return Boolean(navigator.userAgent.match(/. ...

  7. Thinking in Java--笔记(2)

    Everything Is an Object You manipulate objects with references Each programming language has its own ...

  8. Synergy 鼠标和键盘共享软件

    http://symless.com/nightly Synergy 正可以让你的多台电脑共享一套键鼠,甚至还可以共享剪贴板,如同一机多屏,并跨平台支持 .

  9. Mongo聚合函数

    { "_id" : ObjectId("57301c7e5fd5d6e2afa221d1"), "a" : "张三", ...

  10. 7.2.12. MySQL如何优化ORDER BY

    在某些情况中,MySQL可以使用一个索引来满足ORDER BY子句,而不需要额外的排序. 即使ORDER BY不确切匹配索引,只要WHERE子句中的所有未使用的索引部分和所有额外的ORDER BY 列 ...