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

Hint. 小心溢出！

Code:

``````public class Solution {
public int findNthDigit(int n) {
int result = -1;

if (n > 0) {
int a = 1;
long b = 9;
while (n > a * b) {
n -= a * b;
a++;
b *= 10;
}
int start = (int) Math.pow(10, a - 1);
int num = start + (n - 1) / a;
String str = String.valueOf(num);
result = str.charAt((n - 1) % a) - '0';
}

return result;
}
}``````

### 初雪之音

Leetcode 400. Nth Digit

SnailTyan
08/02
0
0
【LeetCode】400 Nth Digit（java实现）

BookShu
2016/10/23
422
0
Clink（Powerful Bash-style command line editing ）

Powerful Bash-style command line editing for cmd.ex 一个类似linux的bash的cmd插件。 我们可以在windows 下的cmd.exe 支持c-a c-e c-b c-f a-b a-f.... 点击clink.bat以后，在运行 clink ......

2014/10/14
0
0
PAT A1023. Have Fun with Numbers (20)

Have Fun with Numbers (20) https://www.patest.cn/contests/pat-a-practise/1023 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Notice tha......

2017/03/05
0
0
Boost组件multi_index_container组合查询实例(续2)

2012/03/09
186
0

java框架学习日志-7（静态代理和JDK代理）

13
0

1.Flink窗口 Window Assigner分配器。 窗口可以是时间驱动的（Time Window，例如：每30秒钟），也可以是数据驱动的（Count Window，例如：每一百个元素）。 一种经典的窗口分类可以分成： 翻...

5
0
my.ini

1

architect刘源源

9
0
docker dns

There is a opensource application that solves this issue, it's called DNS Proxy Server It's a DNS server that solves containers hostnames, if could not found a hostname that mat......

kut

8
0

17
0