https://leetcode.com/contest/5/problems/nth-digit/

刚开始看不懂题意,后来才理解是这个序列连起来的,看一下第几位是几。然后就是数,1位数几个,2位数几个,3位数几个,int范围2e10,所以处理到11位数差不多,仔细算一下可以更少,然后先找到是几位数,然后除以位数,找到这个数是多少,取余看是第几位,然后就可以了。我预处理每位的个数和开始的位置。

 class Solution {
public:
long long d[];
int b[];
int init(int n) {
d[] = ;
d[] = ;
b[] = ;
for (int i = ; i < ; i++) {
d[i] = d[i - ] * ;
b[i] = b[i - ] * ;
}
for (int i = ; i < ; i++) {
d[i] = d[i] * i;
// cout << d[i] << endl;
}
int i = ;
for (i = ; i < ; i++) {
if(d[i] < n)
n -= d[i];
else break;
}
n--;
int t1 = n / i, t2 = n % i;
int k = b[i] + t1;
stringstream ss; string s1;
ss << k; s1 = ss.str();
//cout << t1 << " asd " << t2 << endl;
//cout << s1 << endl;
//reverse(s1.begin(), s1.end());
return s1[t2] - ''; }
int findNthDigit(int n) {
return init(n);
}
};

[leetcode] 400. Nth Digit的更多相关文章

  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. Leetcode 400. Nth digits

    解法一: 一个几乎纯数学的解法 numbers:   1,...,9, 10, ..., 99, 100, ... 999, 1000 ,..., 9999, ... # of digits:   9 ...

  5. 【leetcode❤python】 400. Nth Digit

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

  6. 400. Nth Digit

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

  7. 400 Nth Digit 第N个数字

    在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字.注意:n 是正数且在32为整形范围内 ( n < 231).示例 1:输入:3 ...

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

随机推荐

  1. SCALA编程实例

    SCALA与JAVA很相似,包括类.函数.集合等等的使用.如果你是一个JAVA程序员,你应该会很快上手. 需要注意的是SCALA特有的一些奇葩标志,比如->,比如=>,遇到要注意下. 使用 ...

  2. 【STL学习】map&set

    技术不只是我的工作,也是我的生活,以后的博客中会穿插一些个人的喜悦.愤怒或者感悟,希望大家能够接受. 我所有的一切,比我技术更好的怕是我的脸皮了,昨天收到京东面试没有通过的消息,喊了几句“我好悲伤啊” ...

  3. css中文字体unicode对照表

    为什么要使用Unicode编码代替中文字体 在CSS中使用中文字体通常直接设置字体名称,比如设置字体为宋体:font-family:’宋体’:但因此产生的一个问题是,如果默认编码并不是UTF-8,这会 ...

  4. iOS动画详解(二)

    UIImage常用的绘图操作   一个UIImage对象提供了向当前上下文绘制自身的方法.我们现在已经知道如何获取一个图片类型的上下文并将它转变成当前上下文.   平移操作:下面的代码展示了如何将UI ...

  5. 解决下载Android Build-tools 19.1.0失败

    准备从Eclipse转到Android Studio了.今天尝试Android Studio的时候,被它提醒我SDK的Android Build-tools版本过低,需要升级. 于是打开Android ...

  6. 秀一套每秒处理1500+个事务的profile

    秀一套每秒处理1500+个事务的profile,真实生产环境

  7. 更改OS序列号(slmgr)

    slmgr /ipk 489j-abc-def-hij-mnn slmgr /skms 8.8.8.8:1688 slmgr /ato

  8. Codeforces Round #268 (Div. 1) B. Two Sets 暴力

    B. Two Sets Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/B ...

  9. WebStorm 6.0下运行pomelo项目

    最近想使用WebStorm来写pomelo,初次使用WebStorm,网上找了老半天根本没有介绍WebStorm如何创建或者打开运行pomelo的教程,网易pomelo官网介绍的使用 WebStorm ...

  10. open_table与opened_table --2

    好多人在调优Mysql的时候,总是对open_tables和opend_tables两个参数分别不清. 网上好多解释都是这样的:open_tables:当前打开表的数量opened_tables:当前 ...