在无限的整数序列 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个数字的更多相关文章

  1. C++版 - Leetcode 400. Nth Digit解题报告

    leetcode 400. Nth Digit 在线提交网址: https://leetcode.com/problems/nth-digit/ Total Accepted: 4356 Total ...

  2. 【LeetCode】400. Nth Digit 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. 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 ...

  4. 400. Nth Digit

    这个EASY难度的题怎么感觉比H的还难,昨天没做出来,今天才做出来.. 呃啊..我生 气 啦.. 直接看的答案,耻辱. 1 digit: 1~9 总共1×9个 2 digits: 10~99 总共2× ...

  5. 【leetcode❤python】 400. Nth Digit

    #-*- coding: UTF-8 -*- class Solution(object):    def findNthDigit(self, n):        ""&quo ...

  6. [leetcode] 400. Nth Digit

    https://leetcode.com/contest/5/problems/nth-digit/ 刚开始看不懂题意,后来才理解是这个序列连起来的,看一下第几位是几.然后就是数,1位数几个,2位数几 ...

  7. [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 ...

  8. [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 ...

  9. hdu 1597 find the nth digit

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. Linux下汇编语言学习笔记16 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  2. the apple code

    i know you will forget but 9 you will

  3. CCNA一些要点

    考试范围:     TK640-801(Cisco Certified Network Associate 640-801 ICND Course Notes).     信息单位:     1Byt ...

  4. [Debug] Inspect and Style an Element in DevTools that Normally Disappears when Inactive

    It’s handy to inspect an element in your browser’s DevTools when you need to experiment or tweak it’ ...

  5. 杭电 3555 Bomb

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

  6. 【block第四篇】实现

    -------------------------------------------欢迎查看block连载博客[专栏]--------------------------------------[b ...

  7. java的输入输出流(一)

    java中i/o流是java中核心的一部分,曾经学过.可是理解不够深入,渐渐的也就忘了,如今在从新学习下java的io处理,写下我学习的笔记.便于记忆,和总结归纳: 本文原创,转载请注明:http:/ ...

  8. 合并小图片利器TexturePacker GUI

    合并小图片,能够非常大的节省网络开销.尤其如今的站点非常喜欢使用大量的小图标来做一些友好提示.当然使用图片文字也是一种选择. 只是这里推荐的是TexturePacker GUI ,这个确实是一款利器. ...

  9. 【面试加分项】java自己定义注解之解析注解

    我之前的博客中说明过自己定义注解的声明今天我们来看看怎样对我们自己定义的注解进行使用. 1.我们在程序中使用我们的注解. 上一篇中我们自己定义了一个注解: @Target(ElementType.FI ...

  10. 另类创业招聘(REV#2)

    项目一 项目名:苏格拉底网 项目性质:人才測评为主.辅助以简易人才招聘功能的小众功能站点.项目使用了自主研发的人才測评算法以及人格分类模型(与MBTI非常相似). 项目相关网址:sugeladi.ne ...