400Nth Digit
来源:互联网 发布:cf录视频软件 编辑:程序博客网 时间:2024/06/13 15:36
class Solution(object):
def findNthDigit(self, n):
"""
:type n: int
:rtype: int
"""
charSize = 1
numSize = 9
difit = 1
while n > charSize * numSize:
n -= charSize * numSize
charSize += 1
difit *= 10
numSize = 9 * difit
def findNthDigit(self, n):
"""
:type n: int
:rtype: int
"""
charSize = 1
numSize = 9
difit = 1
while n > charSize * numSize:
n -= charSize * numSize
charSize += 1
difit *= 10
numSize = 9 * difit
return int(str(difit + (n-1) / charSize)[n % charSize-1])
http://www.cnblogs.com/salmd/p/5933715.html
difit为每段的起始值
charsize:表示几位数
numsize表示在某位数总共包含的数值个数
算出给定值所在位数的第几个值中:difit+(n-1)/charsize :因为第一个值已有所以减去第一个值看看有几个周期,有几个周期就在开始值后的第几个位置
n%charsize-1:算出给定值的具体个数所在的位置下标,所在位置的下标从0开始,所以下标位置要减去1
阅读全文
0 0
- LeetCode 400 Nth Digit
- Leetcode 400 Nth Digit
- 400Nth Digit
- Leetcode 400 Nth Digit
- leeetcode 400 Nth Digit
- Nth Digit
- Nth Digit
- Nth Digit
- Nth Digit
- Nth Digit
- 【LeetCode】400 Nth Digit(java实现)
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- hdoj1597find the nth digit
- find the nth digit
- find the nth digit
- 41STL之拷贝和替换算法
- java实现语音播报功能
- HotSpot虚拟机对象探秘
- GreenDao的简单实用
- 2017中国移动互联网测试开发大会第三届早鸟票限时开抢!
- 400Nth Digit
- 获取ip地址
- 使用sina33的SDK在SC3817R上点亮HM1375(分色排版)
- 42STL之算术和生成算法
- 当scrollview 遇到gridview,listview产生的坑
- 滚动和div标签位置和li标签的相对定位,并进行重叠
- selenium geckodriver firefox兼容性问题
- 初窥Linux 之最常用的20条命令
- IDEA创建maven项目-1