0ms cpp


  • 0
    Z
    #include <cmath>
    class Solution {
    public:
        int findNthDigit(int n) {
            int i = 0;
            unsigned long du = 0;
            unsigned long subsum = du;
            while (n > du) {
                n -= du;
                ++i;
                subsum += du;
                du = static_cast<unsigned long>(9 * std::pow(10, i - 1) * i);
            }
            unsigned long target = n / i  + std::pow(10, i - 1);
            if (n % i == 0) {
                return (target - 1) % 10;
            }
            return target / static_cast<unsigned long>(std::pow(10, i - (n % i))) % 10;
            
        }
    };
    

Log in to reply
 

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