400 Nth Digit 第N个数字
在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字。
注意:
n 是正数且在32为整形范围内 ( n < 231)。
示例 1:
输入:
3
输出:
3
示例 2:
输入:
11
输出:
0
说明:
第11个数字在序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... 里是0,它是10的一部分。
详见:https://leetcode.com/problems/nth-digit/description/
C++:
class Solution {
public:
int findNthDigit(int n)
{
long long len = 1, cnt = 9, start = 1;
while (len * cnt < n)
{
n -= len * cnt;
++len;
cnt *= 10;
start *= 10;
}
start += (n - 1) / len;
string t = to_string(start);
return t[(n - 1) % len] - '0';
}
};
参考:https://www.cnblogs.com/grandyang/p/5891871.html
400 Nth Digit 第N个数字的更多相关文章
- C++版 - Leetcode 400. Nth Digit解题报告
leetcode 400. Nth Digit 在线提交网址: https://leetcode.com/problems/nth-digit/ Total Accepted: 4356 Total ...
- 【LeetCode】400. Nth Digit 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- leetcode 400 Add to List 400. Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is ...
- 400. Nth Digit
这个EASY难度的题怎么感觉比H的还难,昨天没做出来,今天才做出来.. 呃啊..我生 气 啦.. 直接看的答案,耻辱. 1 digit: 1~9 总共1×9个 2 digits: 10~99 总共2× ...
- 【leetcode❤python】 400. Nth Digit
#-*- coding: UTF-8 -*- class Solution(object): def findNthDigit(self, n): ""&quo ...
- [leetcode] 400. Nth Digit
https://leetcode.com/contest/5/problems/nth-digit/ 刚开始看不懂题意,后来才理解是这个序列连起来的,看一下第几位是几.然后就是数,1位数几个,2位数几 ...
- [Swift]LeetCode400. 第N个数字 | Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is ...
- [LeetCode] Nth Digit 第N位
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...
- hdu 1597 find the nth digit
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- linux 用户管理、权限管理
1.useradd -[ugGdsce]2.passwd 用户名 ================================================ 1.chmod 2.chown 3. ...
- 解决Android Studio2.0不能使用HttpClient
在build.gradle中的android {}中加上useLibrary 'org.apache.http.legacy'
- HDU 5641 King's Phone【模拟】
题意: 给定一串密码, 判断是否合法. 长度不小于4 不能重复经过任何点 不能跳过中间点,除非中间点已经经过一次. 分析: 3*3直接记录出可能出现在两点之间的点,直接模拟就好. 注意审题,别漏了判断 ...
- Windows堆思维导图--Windows pro sp3
http://bbs.pediy.com/showthread.php?p=1445192#post1445192
- GNS3模拟的硬件
Hardware emulated by GNS3 Cisco 1700 Series 1700s have one or more interfaces on the motherboard, 2 ...
- 在ASP.NET Core 中使用Cookie中间件 (.net core 1.x适用)
在ASP.NET Core 中使用Cookie中间件 ASP.NET Core 提供了Cookie中间件来序列化用户主题到一个加密的Cookie中并且在后来的请求中校验这个Cookie,再现用户并且分 ...
- Nginx/Spring:增加上传文件尺寸限制
Nginx: 1. vi /etc/nginx/nginx.config 2. 在server中增加如下行 # set client body size to 20M # client_max_bod ...
- iOS开发项目实战——Swift实现图片轮播与浏览
近期開始开发一个新的iOS应用,自己决定使用Swift.进行了几天之后,发现了一个非常严峻的问题.那就是无论是书籍,还是网络资源,关于Swift的实在是太少了,随便一搜全都是OC实现某某某功能.就算是 ...
- [Canvas画图] 藏图阁(16) 人体穴位
本节目标: 趁着今天是愚人节.阿伟决定来重温一下学医的那段日子. 有那么一段时间, 阿伟对武侠小说和医学同一时候产生了浓厚的兴趣,当时最想学的就是葵花点穴手, 一阳指之类的点穴功夫.轻轻一点.就能把别 ...
- HDU 1226 超级password
跟POJ 1465 multiple 类是.仅仅只是多了2个条件,长度不能超过500.还有就是 可能不是十进制. bfs+同余定理,就是用 mod 来判重. G++ 15ms 每次枚举一位,然后记录下 ...