【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)
【leetcode❤python】 400. Nth Digit的更多相关文章
- 【LeetCode】400. Nth Digit 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【leetcode❤python】 19. Remove Nth Node From End of List
#-*- coding: UTF-8 -*-#双指针思想,两个指针相隔n-1,每次两个指针向后一步,当后面一个指针没有后继了,前面一个指针的后继就是要删除的节点# Definition for sin ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
- 【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 ...
- 【leetcode❤python】 165. Compare Version Numbers
#-*- coding: UTF-8 -*-class Solution(object): def compareVersion(self, version1, version2): ...
- 【leetcode❤python】 168. Excel Sheet Column Title
class Solution(object): def convertToTitle(self, n): """ :type n: in ...
随机推荐
- 杭电ACM题目分类
基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058. ...
- Cocos2d-x环境搭建
资源列表 官网上下载最新的cocos2d-x-3.3. 安装JDK,Eclipse,CDT插件,ADT插件. 下载Android SDK,更新.因为国内经常访问不了google,用vpn速度也有点慢. ...
- ASP.NET Page执行顺序【转】
一.ASP.NET 母版页和内容页中的事件 母版页和内容页都可以包含控件的事件处理程序.对于控件而言,事件是在本地处理的,即内容页中的控件在内容页中引发事件,母版页中的控件在母版页中引发事件.控件事件 ...
- iOS开发小技巧
1. 解析详情页(是webView)遇到的3个问题: 1.图片太大,超出屏幕范围 2.怎么在webView上面添加一行文字 3.文字太小 1.解决方法 webView.scalesPageToFit ...
- WindowsFormsIntegration.dll
WindowsFormsIntegration.dll的位置如下 C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFrame ...
- Windows平台配置免安装的MySQL
1.下载 官网下载免安装文件(本文使用的是mysql-5.6.33-win32.zip)解压到E:\MySQL\mysql-5.6.33打开E:\MySQL\mysql-5.6.33\my-defau ...
- magento 备份
magento 备份分为“文件备份”和“数据备份” 我们先来讲下“数据备份” 数据备份的方法有 通过数据库软件直接导出magento使用的数据库,使用mysql命名或者phpmyadmin,导出来就好 ...
- 使用Karma 来进行 JavaScript 测试
最近接触了一些新的前端开发知识,主要是利用AngularJS做single page application.我也借这个机会,花了几天时间了解了如何对javascript进行测试. 这里将介绍一些使用 ...
- adop - ERRORMSG: Since earlier patching session failed and you are invoking apply again
$ adop phase=apply patches= hotpatch=yes *******FATAL ERROR******* PROGRAM : (/app/oracle/apps/VIS/f ...
- 如何在page_load方法判断是服务器端控件引发的page_load方法
动态获取单击的服务器端控件的id值 private string getPostBackControlName() { Control control=null; s ...