水题,照着模拟即可
但容易写错,在 pow(10,cnt) 上忘记向上取整wa了几发
class Solution {
public:
int findNthDigit(int n) {
int cnt = 1;
long long int nub = 9;
while( n > nub*cnt ){
n -= cnt*nub;
cnt++;
nub *= 10;
}
int pos = ceil(pow(10,cnt-1));
pos += n/cnt ;
n = n%cnt;
if( n == 0 )pos--,n = cnt;
int t = cnt - n;
while( pos ){
int x = pos%10;
if( t == 0 )return x;
t--;
pos/=10;
}
return pos;
}
};