#-*- 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. GsonUtils.java

    package com.vcredit.ddcash.batch.util; import java.util.ArrayList;import java.util.List; import org. ...

  2. SpringMvc简单实例

    Spring MVC应用一般包括4个步骤: (1)配置web.xml,指定业务层对应的spring配置文件,定义DispatcherServlet; (2)编写处理请求的控制器 (3)编写视图对象,例 ...

  3. 在strut.xml 中使用ognl

    在struts.xml 中使用ognl有两种方面的需求: 1. 在action执行时从struts.xml中读取param标签中的值,然后调用标签name属性相应的set方法对action中的变量赋值 ...

  4. OSI七层与TCP/IP五层网络架构详解

      引用自:http://www.2cto.com/net/201310/252965.html   OSI和TCP/IP是很基础但又非常重要的网络基础知识,理解得透彻对运维工程师来说非常有帮助.今天 ...

  5. 同时使用python2和Python3

    问题:thrift生成的是python2代码,之前使用的是Python3因此需要同时使用两个版本. 方案:将python3的可执行文件重命名为python3(默认为Python),这样使用pyhton ...

  6. 【转】oracle回闪操作

    在9i上执行的操作 查询test表中记录select * from test;删除test表中记录delete from test;获得过去的会话exec dbms_flashback.disable ...

  7. PHP 生成随机字符串与唯一字符串

    说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...

  8. yield return的用法简介

    使用yield return 语句可一次返回一个元素. 迭代器的声明必须满足以下要求: 返回类型必须为 IEnumerable.IEnumerable<T>.IEnumerator 或 I ...

  9. EntityFramework code first 一些常用的约束特性

    参阅: https://msdn.microsoft.com/zh-cn/data/jj591583 1. 主键 public class Test { //名称为 ID 的属性会自动映射为主键(自增 ...

  10. angular 路由去除#号

    1.  路由启动          $locationProvider.html5Mode(true);  通过pushstatex修改url app.js define([ 'angular', & ...