当前位置:网站首页>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';
}
}
边栏推荐
- okcc呼叫中心的订单管理时怎么样的
- 【向量检索研究系列】产品介绍
- Matplotlib draws a histogram and adds values to the graph
- 《LaTex》LaTex数学公式简介「建议收藏」
- Design of short chain
- DAY ONE
- How to find out if the U disk file of the computer reinstallation system is hidden
- PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
- DAY FOUR
- PostgreSQL高可用之repmgr(1主2从+1witness)+Pgpool-II实现主从切换+读写分离
猜你喜欢
MVC and MVVM
GPIO簡介
DAY ONE
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
What is a responsive object? How to create a responsive object?
Matplotlib draws a histogram and adds values to the graph
Pytest multi process / multi thread execution test case
量子时代计算机怎么保证数据安全?美国公布四项备选加密算法
Hydrogen future industry accelerates | the registration channel of 2022 hydrogen energy specialty special new entrepreneurship competition is opened!
Cas d'essai fonctionnel universel de l'application
随机推荐
rancher集成ldap,实现统一账号登录
A way of writing SQL, update when matching, or insert
Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
Compile logisim
Rider离线使用Nuget包的方法
MIT 6.824 - Raft学生指南
基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
陀螺仪的工作原理
编译logisim
pytest多进程/多线程执行测试用例
Geo data mining (III) enrichment analysis of go and KEGG using David database
Close unregistering application XXX with Eureka with status down after Eureka client starts
基于SSM框架实现的房屋租赁管理系统
Automatic test tool katalon (WEB) test operation instructions
"Latex" Introduction to latex mathematical formula "suggestions collection"
js导入excel&导出excel
Why is bat still addicted to 996 when the four-day working system is being tried out in Britain?
MATLIB reads data from excel table and draws function image
三句话简要介绍子网掩码
谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url