/**
* @author xnl
* @Description:
* @date: 2022/7/6 22:43
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.findNthDigit(3));
}
public int findNthDigit(int n) {
int digit = 1; // 位数
long start = 1; // 起点大小
long count = 9; // 当前位的最大值、
// 找到所属的位置
while (n > count){
n -= count;
start *= 10;
digit += 1;
count = start * digit * 9;
}
// 定位到对应的数字
long num = start + (n - 1) / digit;
// 定位到对数字对应的下标
return Long.toString(num).charAt((n - 1) % digit) -'0';
}
}
力扣:剑指 Offer 44. 数字序列中某一位的数字
最新推荐文章于 2025-12-04 23:36:16 发布
博客涉及LeetCode与Java算法相关内容,虽未给出具体内容,但从标签可知围绕LeetCode平台,运用Java语言进行算法相关探讨。

1225

被折叠的 条评论
为什么被折叠?



