【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 ...
随机推荐
- 【iCore3 双核心板】例程十三:SDIO实验——读取SD卡信息
实验指导书及代码包下载: http://pan.baidu.com/s/1hqM787E iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- https加密解密过程详解
要点: https协议对传输内容进行加密,具有更强的安全性,防止被抓包后解析出请求内容. https是建立在ssl之上的http协议. 服务器支持https协议必须安装一套数字证书,所谓数字证书就是一 ...
- XE系列资源文件的奇怪问题
这是一个关于资源文件的故事.......-_- 今天写一个功能测试Demo, 为了省事直接在工程文件里Resources And Images里添加了几个图片, 类型都是默认的RCDATA 然后直接就 ...
- Mysql新建表,插入中文时报错“Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column”问题
有时候我们在往数据库中输入信息时,如果输入的内容是中文,会报错“Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column”. 例如: ...
- 《Linux内核设计与实现》CHAPTER18阅读梳理
<Linux内核设计与实现>CHAPTER18阅读梳理 [学习时间:2hours] [学习内容:bug的来源分析:bug调试途径] 一.bug来源 1.内核中的bug 内核中的bug表现得 ...
- ubifs物理存储
Ubifs通过ubi管理MTD设备,ubi的LEB随机映射PEB,其本身占用一部分PEB,具体文件存储情况分析如下. 1. Ubi中不管是是逻辑块号还是物理块号都是从0开始的.一般情况下,Nandfl ...
- Aggregate
对序列应用累加器函数. /// <summary> /// 计算校验和,SUM /// </summary> public byte CalculateCheckSum(byt ...
- DNS协议
DNS Message: Header 消息头部 Question DNS请求 Answer 回答请求的资源记录(Resource Record(s)) Authority 指向域的资 ...
- c# ConfigurationSection
怎么把自己的配置文件配置到app.config中? 方案1:在app.config中添加 <!--应用配置--> <appSettings configSource="Co ...
- 湖大OJ-实验C----NFA转换为DFA
实验C----NFA转换为DFA Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit us ...