400. Nth Digit
来源:互联网 发布:手机时间与网络同步 编辑:程序博客网 时间:2024/05/21 09:22
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.
public class Solution { public int findNthDigit(int n) { int len = 1; int start = 1; long cnt = 9; while (n > len * cnt) { n -= len * cnt; len++; cnt *= 10; start *= 10; } start += (n-1) / len; String s = Integer.toString(start); return Character.getNumericValue(s.charAt((n-1) % len)); }}
0 0
- 【Leetcode】400. Nth Digit
- 400. Nth Digit
- leetcode 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit (leetcode) 。。。
- [LeetCode]400. Nth Digit
- [leetcode] 400. Nth Digit
- 400. Nth Digit
- [LeetCode]--400. Nth Digit
- 400. Nth Digit
- leetcode 400. Nth Digit
- LeetCode 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit
- [leetcode]400. Nth Digit
- Leetcode 400. Nth Digit
- 400. Nth Digit
- 结构
- 如何进行良好的程序设计(1)
- Reverse Integer
- 2017.03.04【NOIP 普及组】模拟赛C组 T4:泽泽在埃及
- 7.1 printf与scanf
- 400. Nth Digit
- C语言深度解剖第一章笔记
- 编写自己的LinkedList
- 第八条 覆盖equals请遵守通用的约定(二)
- 数据类型初阶
- hbase插入数据
- ZooKeeper源码学习笔记(3)--Cluster模式下的ZooKeeper
- Matlab横坐标轴去掉科学计数法
- uboot配置分析之make100ask24x0_config分析