当前位置:网站首页>Leecode brush questions record sword finger offer 44 A digit in a sequence of numbers
Leecode brush questions record sword finger offer 44 A digit in a sequence of numbers
2022-07-07 00:12:00 【Why is there a bug list】
topic
The numbers are in 0123456789101112131415… Serializes the format of a string into a sequence of characters . In this sequence , The first 5 position ( From the subscript 0 Start counting ) yes 5, The first 13 Is it 1, The first 19 Is it 4, wait .
Please write a function , Ask for any n The number corresponding to bit .
Example 1:
Input :n = 3
Output :3
Example 2:
Input :n = 11
Output :0
Limit :
0 <= n < 2^31
answer
class Solution {
public int findNthDigit(int n) {
int digit = 1;
long start = 1;
long count = 9;
while (n > count) {
// 1.
n -= count;
digit += 1;
start *= 10;
count = digit * start * 9;
}
long num = start + (n - 1) / digit; // 2.
return Long.toString(num).charAt((n - 1) % digit) - '0';
}
}
边栏推荐
- 1000 words selected - interface test basis
- 1000字精选 —— 接口测试基础
- 陀螺仪的工作原理
- Supersocket 1.6 creates a simple socket server with message length in the header
- System activity monitor ISTAT menus 6.61 (1185) Chinese repair
- DAY FOUR
- What is a responsive object? How to create a responsive object?
- [vector retrieval research series] product introduction
- Oracle EMCC 13.5 environment in docker every minute
- Use source code compilation to install postgresql13.3 database
猜你喜欢

STM32通过串口进入和唤醒停止模式

DevOps可以帮助减少技术债务的十种方式

2022/2/11 summary

matplotlib画柱状图并添加数值到图中

File and image comparison tool kaleidoscope latest download

沉浸式投影在线下展示中的三大应用特点

专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统

Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools

Cas d'essai fonctionnel universel de l'application

How rider uses nuget package offline
随机推荐
STM32 enters and wakes up the stop mode through the serial port
Three sentences to briefly introduce subnet mask
Core knowledge of distributed cache
Design of short chain
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
使用yum来安装PostgreSQL13.3数据库
Server SMP, NUMA, MPP system learning notes.
【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
matplotlib画柱状图并添加数值到图中
Wechat applet UploadFile server, wechat applet wx Uploadfile[easy to understand]
[automated testing framework] what you need to know about unittest
How rider uses nuget package offline
App general function test cases
DAY THREE
[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
Unity color palette | color palette | stepless color change function
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
【CVPR 2022】半监督目标检测:Dense Learning based Semi-Supervised Object Detection
Common modification commands of Oracle for tables
MIT 6.824 - raft Student Guide