class Solution {
public:
int findNthDigit(int n) {
int digit = 1;
long long t = 1;
int ans = 0;
while(true){
if(digit * 9 * t < n){
n = n - digit * 9 * t;
digit += 1;
t *= 10;
}
else {
ans = t - 1 + (n + digit - 1) / digit;
n -= (ans - t ) * digit;
break;
}
}
vector<int> hehe;
while(ans > 0){
hehe.push_back(ans % 10);
ans /= 10;
}
return hehe[hehe.size()-n];
}
};Leetcode 400. Nth Digit
最新推荐文章于 2025-12-04 23:36:16 发布
本文介绍了一个C++方法findNthDigit,用于找到正整数序列中的第N位数字。通过计算不同位数区间内的起始值和偏移量,最终定位到目标数字及其具体位置。
2269

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



