当前位置:网站首页>[Jianzhi offer] interview question 44 A digit in a sequence of numbers
[Jianzhi offer] interview question 44 A digit in a sequence of numbers
2022-06-22 21:02:00 【LuZhouShiLi】
Interview questions 44. A digit in a sequence of numbers
subject
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
Ideas
Looking for a regular , Thank you very much
https://leetcode.cn/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/solution/mian-shi-ti-44-shu-zi-xu-lie-zhong-mou-yi-wei-de-6/
Code
class Solution {
public int findNthDigit(int n) {
int digit = 1;
long start = 1;
long count = 9;
while(n > count)
{
n -= count;
digit += 1;
start *= 10;
count = digit * start * 9;
}
// determine n The number in which
long num = start + (n - 1) / digit;
// determine N stay num Which digit of
return Long.toString(num).charAt((n - 1) % digit) - '0';
}
}
边栏推荐
- NumPy学习笔记(六)——sum()函数
- [observation] innovation in the software industry has entered a "new cycle". How can we make a new start in the changing situation?
- The real king of cache
- 73-找到业务高峰时段的sql示例(报表开发类)
- Feign FAQ summary
- 启牛送的券商账户是安全的吗?启牛提供的券商账户是真的?
- Scheduling with Testing
- Ultrafast transformers | redesign vit with res2net idea and dynamic kernel size, surpassing mobilevit
- 密码学系列之:PKI的证书格式表示X.509
- R 语言 wine 数据集可视化
猜你喜欢
![[observation] innovation in the software industry has entered a](/img/b8/232ce6bc41a4154f6c9d48b0819d8f.png)
[observation] innovation in the software industry has entered a "new cycle". How can we make a new start in the changing situation?

Easyclick fixed status log window

The access succeeds but an exception is thrown: could not find acceptable representation

【文末送书】火遍全网的AI给老照片上色,这里有一份详细教程!

字节跳动提出轻量级高效新型网络MoCoViT,在分类、检测等CV任务上性能优于GhostNet、MobileNetV3!...

R language organdata dataset visualization

R language CO2 dataset visualization

The road to systematic construction of geek planet business monitoring and alarm system

一行代码为特定状态绑定SwiftUI视图动画

Overview of common loss functions for in-depth learning: basic forms, principles and characteristics
随机推荐
Numpy learning notes (6) -- sum() function
78-生产系统不改代码解决SQL性能问题的几种方法
超快变形金刚 | 用Res2Net思想和动态kernel-size再设计 ViT,超越MobileViT
75-当left join遇到子查询
Performance test (I)
模拟串口UART的实现
One picture decoding opencloudos community open day
R 语言 UniversalBank.csv“ 数据分析
真正的缓存之王Caffine Cache
Can financial products be redeemed on weekends?
A Dynamic Near-Optimal Algorithm for Online Linear Programming
mysql8.0忘记密码的详细解决方法
MYSQL 几个常用命令使用
字节跳动提出轻量级高效新型网络MoCoViT,在分类、检测等CV任务上性能优于GhostNet、MobileNetV3!...
The real king of cache
88-被广为流传的参数优化, 是蜜糖还是毒药?
Alibaba cloud video on demand playback error, console access code:4400
C语言中int和char的对应关系
Easyclick update Gallery
Easyclick fixed status log window