(LeetCode)Nth Digit --- 第几位数字
来源:互联网 发布:java 敏捷开发框架 编辑:程序博客网 时间:2024/04/30 22:39
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...
Note:
n is positive and will fit within the range of a 32-bit signed integer (n < 231).
Example 1:
Input:3Output:3
Example 2:
Input:11Output:0Explanation:The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.
Subscribe to see which companies asked this question
解题分析:
此题目的意思就是将所有的数字打开,从第一个往后数,看第几位是哪个数字?
基本的思路是一位时当0 ~ 9时候,共十个数,
两位时,10 ~ 99 共有 90个
三位时,。。。。。。。。。。。
我们可以计算范围,然后一次去掉已经计算出来的位数,然后算出,数字。
# -*- coding:utf-8 -*-__author__ = 'jiuzhang'class Solution(object): def findNthDigit(self, n): if n < 0: return 0 count = 9 start = 1 length = 1 while n > (length * count): n -= length * count length += 1 start *= 10 count *= 10 start += (n - 1)/length return int((str(start)[(n - 1)%length]))
0 0
- (LeetCode)Nth Digit --- 第几位数字
- Leetcode 400. Nth Digit 第n个数字 解题报告
- leetcode 400. Nth Digit 第n个数字是什么
- 【Leetcode】400. Nth Digit
- LeetCode 400 Nth Digit
- [Leetcode] Nth Digit
- leetcode 400. Nth Digit
- 400. Nth Digit (leetcode) 。。。
- [LeetCode]400. Nth Digit
- [leetcode] 400. Nth Digit
- [LeetCode]--400. Nth Digit
- leetcode 400. Nth Digit
- LeetCode Nth Digit
- LeetCode 400. Nth Digit
- [leetcode]400. Nth Digit
- Leetcode 400. Nth Digit
- LeetCode 400. Nth Digit
- 【LeetCode】 400. Nth Digit
- MFC实现TabCtrl
- sql server 查询镜像端点和删除
- vi 替换方法
- Elevator
- 1046: [HAOI2007]上升序列
- (LeetCode)Nth Digit --- 第几位数字
- 将普通应用程序添加到系统服务 windows server2003
- html段落标签
- (例子)PHP 数据抓取小例子
- 被告不清律师如何打官司的解决方法是什么?
- 总结一些页面常见的跳转方法
- android怎么用APK调用JNI简单实例
- 面试算法题:求出所有N位的二进制数
- 爬虫,索引,PageRank,搜索,综合例子