【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 ...
随机推荐
- Redis菜鸟汇总
1.是完全开源免费的,用C语言编写的,遵守BSD协议,是一个高性能的(key/value)分布式内存数据库,基于内存运行并支持持久化的NoSQL数据库,是当前最热门的NoSql数据库之一,也被人们称为 ...
- Python强化训练笔记(二)——元组元素的命名
对于一个元组如: >>> s1 = ('Jim', 21, 'boy', '5788236@qq.com') 我们要得到该对象的名字,年龄,性别及邮箱的方法为s1[0],s1[1], ...
- objective-c基础教程——学习小结
objective-c基础教程——学习小结 提纲: 简介 与C语言相比要注意的地方 objective-c高级特性 开发工具介绍(cocoa 工具包的功能,框架,源文件组织:XCode使用介绍) ...
- ExtJS笔记 Proxy
Proxies are used by Stores to handle the loading and saving of Model data. Usually developers will n ...
- 淘宝天猫网站停止支持IE6、IE7浏览器,你还在用xp吗?
2016年4月14日,是科比正式告别篮球的最后一场球赛.大家都在忙着各种纪念和怀念着看科比打球的青葱岁月.不过已经完美谢幕.而我们今天要说的是微软的IE6.IE7浏览器.淘宝网和天猫商城正式停止支持I ...
- javaWeb中servlet开发(3)——Servlet生命周期
生命周期:是一个程序的存在周期,servlet由于是受容器的管理,所以容器来决定其生命周期 1.servlet生命周期 2.servlet生命周期对应的方法 3.servlet生命周期代码 publi ...
- Characteristics of Some CISCs, RISCs, and Superscalar Processors
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Although RISC archite ...
- [转]Android SHA1与Package获取方式
转自高德地图LBS Android SHA1与Package获取方式 获取应用包名 打开Android 应用工程的 AndroidManifest.xml配置文件,package 属性所对应的内容为应 ...
- ios数据库常用sql语句
SQlite常用语句 由于sql语句在程序代码中以字符串的形式存在,没有代码提示,不细心很容易出错,而且不容易被查出来.sql语句字符串是单引号. 写sql语句的时候一定要细心呀.如果写不好可以找公司 ...
- LeetCode Reconstruct Itinerary
原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/ 题目: Given a list of airline tickets rep ...