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 ...
随机推荐
- codevs 1378 选课
题目描述 Description 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了N(N<300)门的选修课程,每个学生可选课程的数量M是给定的.学生选修 ...
- [bzoj1207][HNOI2004]打鼹鼠_动态规划
打鼹鼠 bzoj-1207 HNOI-2004 题目大意:题目链接. 注释:略. 想法: $dp_i$表示打到了第$i$个鼹鼠时最多打了多少个鼹鼠. $O(n)$转移即可. 总时间复杂度$O(n^2) ...
- Django学习系列之CSRF
Django CSRF 什么是CSRF CSRF, Cross Site Request Forgery, 跨站点伪造请求.举例来讲,某个恶意的网站上有一个指向你的网站的链接,如果 某个用户已经登录到 ...
- [Java Spring] Spring Annotation Configuration Using XML
Add context to our application. main/resources/applicationContext.xml: <?xml version="1.0&qu ...
- C#.NET如何判断是否有缺少的using
调试的时候会报错,红色的波浪线表示出错的位置,右击即可找到对应的using
- Linux系统调用过程分析
參考: <Linux内核设计与实现> 0 摘要 linux的系统调用过程: 层次例如以下: 用户程序------>C库(即API):INT 0x80 ----->system_ ...
- 找了两个node+vue-cli+mogodb的小项目学学
实现的博客系统,自己抽时间搭建看看 https://www.cnblogs.com/yesyes/p/7188331.html https://github.com/chaohangz/vueBlog
- 【树形dp小练】HDU1520 HDU2196 HDU1561 HDU3534
[树形dp]就是在树上做的一些dp之类的递推,由于一般须要递归处理.因此平庸情况的处理可能须要理清思路.昨晚開始切了4题,作为入门训练.题目都很easy.可是似乎做起来都还口以- hdu1520 An ...
- [Python] How to unpack and pack collection in Python?
It is a pity that i can not add the video here. As a result, i offer the link as below: How to unpa ...
- MyEclipse,Eclipse注释规范模板
注释的作用:myeclipse中java文件头注释格式设置,最终可用于javadoc.exe生成API文档,同时提高了代码的可读性 设置方法: windows->preferences-> ...