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 ...
随机推荐
- POJ 2828 Buy Tickets (线段树 || 树状数组)
题目大意 一些小朋友在排队,每次来一个人,第i个人会插到第x个人的后面.权值为y.保证x∈[0,i-1]. 按照最后的队伍顺序,依次输出每个人的权值. 解题分析 好气吖.本来是在做splay练习,然后 ...
- Ubuntu12.04之vi的问题
版本:ubuntu12.04. 问题:vi不能正常使用方向键与退格键. 原因:ubuntu系统自带的 vi 不完整导致. 解决方法:安装完整的vi,sudo apt-get install vim-g ...
- 解决Android Studio2.0不能使用HttpClient
在build.gradle中的android {}中加上useLibrary 'org.apache.http.legacy'
- Android GIS开发系列-- 入门季(12) 显示载天地图
在项目中可以经常需要动态加载一些图层,像投影地图服务.投影地图服务器.其实网上有大量这样的服务,比如天地图官网, . 随便点开一个服务,里面有相关的信息.那如何加载这样图层服务呢. 一.首先感谢这篇博 ...
- server证书安装配置指南(Tomcat 6)
一. 生成证书请求 1. 安装JDK 安装Tomcat须要JDK支持. 假设您还没有JDK的安装.则能够參考 Java SE Development Kit (JDK) 下载. 下载地址: ...
- CBO之Full Table Scan - FTS算法
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/44261859 ************************************** ...
- SpringMVC_1
//@SessionAttributes(value={"user"},types={String.class}) @Controller public class SpringM ...
- [Android6.0][RK3399] 双屏异显代码实现流程分析(一)【转】
本文转载自:http://blog.csdn.net/dearsq/article/details/55049182 Platform: RK3399 OS: Android 6.0 Version: ...
- ubuntu14安装docker-ce
先卸载旧的docker sudo apt-get remove docker docker-engine docker.io docker-ce 通过HTTPS使用存储库(repository) su ...
- 改造系统alert
/************************************************************************* * 改造系统alert * param str 传 ...