[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 is positive and will fit within the range of a 32-bit signed integer (n < 231).
Example 1:
Input:
3 Output:
3
Example 2:
Input:
11 Output:
0 Explanation:
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.
class Solution {
public:
int findNthDigit(int n) {
long long len = , cnt = , start = ;
while (n > len * cnt) {
n -= len * cnt;
++len;
cnt *= ;
start *= ;
}
start += (n - ) / len;
string t = to_string(start);
return t[(n - ) % len] - '';
}
};
参考资料:
https://discuss.leetcode.com/topic/59314/java-solution
LeetCode All in One 题目讲解汇总(持续更新中...)
[LeetCode] Nth Digit 第N位的更多相关文章
- Leetcode: Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...
- LeetCode——Nth Digit
Question Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... ...
- 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 ...
- Nth Digit | leetcode
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...
- 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 ...
- [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 ...
- HDU-1597find the nth digit,超短代码一遍过,啦啦啦啦~~
find the nth digit Time Limit: 10 ...
- Martyr2项目实现——Number部分的问题求解 (1) Find Pi to Nth Digit
Martyr2项目实现--Number部分的问题求解 (1) Find Pi to Nth Digit Find Pi to Nth Digit 问题描述: Find PI to the Nth Di ...
随机推荐
- 【基于WPF+OneNote+Oracle的中文图片识别系统阶段总结】之篇四:关于OneNote入库处理以及审核
篇一:WPF常用知识以及本项目设计总结:http://www.cnblogs.com/baiboy/p/wpf.html 篇二:基于OneNote难点突破和批量识别:http://www.cnblog ...
- 一个前端所需具备的PS能力
前端网页设计+静态实现案例 放一个2天半内给某公司完成的(设计 + 静态实现)的案例吧,静态阴影用CSS3实现的http://www.cnblogs.com/MuYunyun/p/5693615.ht ...
- C站投稿189网盘视频源(UP主篇)
C站投稿189网盘视频源(UP主篇) 现在C站(吐槽弹幕网)的视频来源基本靠的都是189网盘,比如番剧区的每个视频基本来源于此,不像AB两站,拥有自己的资源服务器,为啥呢?没钱啊.都是外来的视频.本站 ...
- Python基础(三)
本章内容: 深浅拷贝 函数(全局与局部变量) 内置函数 文件处理 三元运算 lambda 表达式 递归(斐波那契数列) 冒泡排序 深浅拷贝 一.数字和字符串 对于 数字 和 字符串 而言,赋值.浅拷贝 ...
- css3新单位学习
vw,vh,vmin,vmax vw 1vw = 视窗width*1% vh 1vh = 视窗heihgt*1% 如果视窗的宽度小于高度,1vmin = 1vw,如果视窗宽度大于高度,1vmin = ...
- c#使用Split分割换行符 \r\n
c# 使用Split分割 换行符,方法如下(其余方法有空再添加): string str = "aa" + "\r\n" + "bb"; ...
- 【夯实PHP基础】PHP的反射机制
本文地址 分享提纲: 1. 介绍 2. 具体例子 2.1 创建Persion类 2.2 反射过程 2.3 反射后使用 1. 介绍 -- PHP5添加了一项新的功能:Reflection.这个功能使得p ...
- 隔天开启tomcat spring报错
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...
- [连载]《C#通讯(串口和网络)框架的设计与实现》- 6.通讯控制器的设计
目 录 第六章 通讯控制器的设计... 2 6.1 控制器接口... 2 6.2 串口控制器... 3 6.3 ...
- SSH远程会话管理工具 - screen使用教程
一.screen命令是什么? Screen是一个可以在多个进程之间多路复用一个物理终端的全屏窗口管理器.Screen中有会话的概念,用户可以在一个screen会话中创建多个screen窗口,在每一个s ...