当前位置:网站首页>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';
}
}
边栏推荐
- DAY ONE
- pytest多进程/多线程执行测试用例
- [2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
- Liuyongxin report | microbiome data analysis and science communication (7:30 p.m.)
- 2022/2/10 summary
- 在docker中快速使用各个版本的PostgreSQL数据库
- MIT 6.824 - raft Student Guide
- Wind chime card issuing network source code latest version - commercially available
- 【CVPR 2022】半监督目标检测:Dense Learning based Semi-Supervised Object Detection
- web渗透测试是什么_渗透实战
猜你喜欢

The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance

Matplotlib draws a histogram and adds values to the graph

17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster

【自动化测试框架】关于unittest你需要知道的事

GPIO简介

Rider离线使用Nuget包的方法

Yaduo Sangu IPO

2022/2/10 summary
![Tourism Management System Based on jsp+servlet+mysql framework [source code + database + report]](/img/41/94488f4c7627a1dfcf80f170101347.png)
Tourism Management System Based on jsp+servlet+mysql framework [source code + database + report]
![[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test](/img/8d/b59cf466031f36eb50d4d06aa5fbe4.jpg)
[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
随机推荐
vector的使用方法_vector指针如何使用
DAY FIVE
Unity color palette | color palette | stepless color change function
DAY SIX
【CVPR 2022】半监督目标检测:Dense Learning based Semi-Supervised Object Detection
Why is bat still addicted to 996 when the four-day working system is being tried out in Britain?
Rider离线使用Nuget包的方法
Compile logisim
Common modification commands of Oracle for tables
ldap创建公司组织、人员
编译logisim
Penetration test --- database security: detailed explanation of SQL injection into database principle
Competition between public and private chains in data privacy and throughput
web渗透测试是什么_渗透实战
Automatic test tool katalon (WEB) test operation instructions
How to answer the dualistic opposition of Zhihu
Local deployment Zeppelin 0.10.1
DAY FOUR
Every year, 200 billion yuan is invested in the chip field, and "China chip" venture capital is booming
App general function test cases