当前位置:网站首页>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';
}
}
边栏推荐
- 使用源码编译来安装PostgreSQL13.3数据库
- DAY THREE
- How does win11 restore the traditional right-click menu? Win11 right click to change back to traditional mode
- Use source code compilation to install postgresql13.3 database
- Automatic test tool katalon (WEB) test operation instructions
- app通用功能测试用例
- Things like random
- SQL的一种写法,匹配就更新,否则就是插入
- 【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
- Use Yum or up2date to install the postgresql13.3 database
猜你喜欢
Racher integrates LDAP to realize unified account login
Newsletter L Huobi ventures is in-depth contact with genesis public chain
DAY THREE
pytest多进程/多线程执行测试用例
How can computers ensure data security in the quantum era? The United States announced four alternative encryption algorithms
Yaduo Sangu IPO
Cas d'essai fonctionnel universel de l'application
沉浸式投影在线下展示中的三大应用特点
matplotlib画柱状图并添加数值到图中
GPIO簡介
随机推荐
Quickly use various versions of PostgreSQL database in docker
"Latex" Introduction to latex mathematical formula "suggestions collection"
After leaving a foreign company, I know what respect and compliance are
在Docker中分分钟拥有Oracle EMCC 13.5环境
MATLIB reads data from excel table and draws function image
app通用功能测试用例
PDF文档签名指南
Close unregistering application XXX with Eureka with status down after Eureka client starts
[212] what are three methods for PHP to send post requests
MATLIB从excel表中读取数据并画出函数图像
自动化测试工具Katalon(Web)测试操作说明
pinia 模块划分
App general function test cases
DAY FIVE
How does win11 restore the traditional right-click menu? Win11 right click to change back to traditional mode
Unity 颜色板|调色板|无级变色功能
PostgreSQL使用Pgpool-II实现读写分离+负载均衡
js导入excel&导出excel
Three sentences to briefly introduce subnet mask
DAY FOUR