class Solution {
public:
int findNthDigit(int n) {
/*
* 首先定位到包含n的这个数字有几位
* 然后定位到包含n的这个数字是什么
* 最后定位到n是这个数字的第几位
*/
long digit=1,base=9,ith=1;//digit表示位数 base 表示digit位数的数字有多少个
while(n>digit*base)
{
n-=(digit*base);
ith+=base;
digit++;
base*=10;
}
return to_string(ith+(n-1)/digit)[(n-1)%digit]-'0';
}
};
400. Nth Digit
最新推荐文章于 2021-08-07 09:43:12 发布