当前位置:网站首页>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';
}
}
边栏推荐
- Use source code compilation to install postgresql13.3 database
- 量子时代计算机怎么保证数据安全?美国公布四项备选加密算法
- PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
- How about the order management of okcc call center
- 使用源码编译来安装PostgreSQL13.3数据库
- vector的使用方法_vector指针如何使用
- What is AVL tree?
- 【精品】pinia 基于插件pinia-plugin-persist的 持久化
- Basic chart interpretation of "Oriental selection" hot out of circle data
- [vector retrieval research series] product introduction
猜你喜欢
System activity monitor ISTAT menus 6.61 (1185) Chinese repair
DAY ONE
2022 PMP project management examination agile knowledge points (9)
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Every year, 200 billion yuan is invested in the chip field, and "China chip" venture capital is booming
DAY FIVE
DAY TWO
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
Gradle knowledge generalization
1000 words selected - interface test basis
随机推荐
【精品】pinia 基于插件pinia-plugin-persist的 持久化
App general function test cases
《LaTex》LaTex数学公式简介「建议收藏」
DAY FIVE
Core knowledge of distributed cache
Introduction au GPIO
(leetcode) sum of two numbers
2022/2/10 summary
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
DAY SIX
Personal digestion of DDD
Use source code compilation to install postgresql13.3 database
MySQL主从之多源复制(3主1从)搭建及同步测试
Basic chart interpretation of "Oriental selection" hot out of circle data
Pinia module division
使用yum来安装PostgreSQL13.3数据库
app通用功能测试用例
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
Building lease management system based on SSM framework
2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial