class Solution {
public:
int findNthDigit(int n) {
/*
1 10
2 90
3 900
4 9000
5 90000
6 900000
7 9000000
*/
if(n<=9)return n;
n-=9;
long long nm=90,tp=2,num=10;
while(1){
if(nm * tp>=n){
//tp位数,有nm个
int z=(n-1)/tp + 1,c=n%tp;
if(c==0)c=tp;
int tm=num+z-1;
vector<int>ans;
while(tm){
ans.push_back(tm%10);
tm/=10;
}
return ans[ans.size()-c];
break;
}
n-=nm * tp;
nm*=10;
num*=10;
tp++;
}
return 0;
}
};