当前位置:网站首页>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';
}
}
边栏推荐
- 谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url
- Oracle中使用包FY_Recover_Data.pck来恢复truncate误操作的表
- Pdf document signature Guide
- 在Docker中分分钟拥有Oracle EMCC 13.5环境
- System activity monitor ISTAT menus 6.61 (1185) Chinese repair
- DevOps可以帮助减少技术债务的十种方式
- 17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
- pytest多进程/多线程执行测试用例
- Three sentences to briefly introduce subnet mask
- Quickly use various versions of PostgreSQL database in docker
猜你喜欢

DAY FIVE

What is AVL tree?

Three application characteristics of immersive projection in offline display

Devops can help reduce technology debt in ten ways

量子时代计算机怎么保证数据安全?美国公布四项备选加密算法

What can the interactive slide screen demonstration bring to the enterprise exhibition hall

2022/2/11 summary

DAY FIVE

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

Matplotlib draws a histogram and adds values to the graph
随机推荐
Three sentences to briefly introduce subnet mask
【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
使用yum来安装PostgreSQL13.3数据库
Do you still have to rely on Simba to shout for a new business that is Kwai?
After leaving a foreign company, I know what respect and compliance are
PostgreSQL uses pgpool II to realize read-write separation + load balancing
web渗透测试是什么_渗透实战
Unity 颜色板|调色板|无级变色功能
Huawei mate8 battery price_ Huawei mate8 charges very slowly after replacing the battery
rancher集成ldap,实现统一账号登录
Basic chart interpretation of "Oriental selection" hot out of circle data
Racher integrates LDAP to realize unified account login
陀螺仪的工作原理
DAY TWO
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
Clipboard management tool paste Chinese version
1000字精选 —— 接口测试基础
谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url
Introduction au GPIO
2022 PMP project management examination agile knowledge points (9)