same idea, just change a little for step 2

...

class Solution {

public:

int findNthDigit(int n) {

long base = 9, digits = 1;

while (n - base * digits > 0)

{

n -= base * digits;

base *= 10;

digits ++;

}

```
int num=pow(10,digits-1)+(n-1)/digits;
int index=(n-1)%digits+1;
for (int i = index; i < digits; i ++)
num /= 10;
return num % 10;
}
```

};