simple C++ solution


  • 0
    W
    class Solution {
    public:
        int findNthDigit(int n) {
            int count = 1;
            while (true) {
                int tmp = count * pow(10, count - 1) * 9;
                if (n - tmp <= 0) break;
                n -= tmp;
                count++;
            }
            int n_tmp = pow(10, count - 1) + ceil(1.0 * n / count) - 1;
            int n_mod = n % count == 0 ? count : n % count;
            return (n_tmp / (int)pow(10, count - n_mod)) % 10;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.