Problem
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...
Note:
n is positive and will fit within the range of a 32-bit signed integer (n < 231).
Example
Input:
3
Output:
3
Input:
11
Output:
0
Code
static int var = [](){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}();
class Solution {
public:
int findNthDigit(int n) {
long i = 1;
for(long count=9;n>i*count;i++,count*=10){
n-=i*count;
}
return to_string(pow(10,i-1)+(n-1)/i)[(n-1)%i]-'0';
}
};