当前位置:网站首页>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';
}
}
边栏推荐
- Operation test of function test basis
- app通用功能测试用例
- Oracle EMCC 13.5 environment in docker every minute
- ldap创建公司组织、人员
- 自动化测试工具Katalon(Web)测试操作说明
- js导入excel&导出excel
- What can the interactive slide screen demonstration bring to the enterprise exhibition hall
- 2022/2/12 summary
- Matplotlib draws a histogram and adds values to the graph
- 【自动化测试框架】关于unittest你需要知道的事
猜你喜欢
【自动化测试框架】关于unittest你需要知道的事
DAY TWO
GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析
app通用功能测试用例
Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work
DAY SIX
2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial
Geo data mining (III) enrichment analysis of go and KEGG using David database
Introduction to GPIO
MATLIB从excel表中读取数据并画出函数图像
随机推荐
Oracle中使用包FY_Recover_Data.pck来恢复truncate误操作的表
陀螺仪的工作原理
System activity monitor ISTAT menus 6.61 (1185) Chinese repair
The largest single investment in the history of Dachen was IPO today
17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
C language input / output stream and file operation [II]
Business process testing based on functional testing
Wind chime card issuing network source code latest version - commercially available
Who said that new consumer brands collapsed? Someone behind me won
Gradle knowledge generalization
Cas d'essai fonctionnel universel de l'application
What is web penetration testing_ Infiltration practice
Design of short chain
Rider离线使用Nuget包的方法
DAY FOUR
三句话简要介绍子网掩码
MIT 6.824 - Raft学生指南
After leaving a foreign company, I know what respect and compliance are
MATLIB从excel表中读取数据并画出函数图像
《LaTex》LaTex数学公式简介「建议收藏」