c++ solution


  • 0
    B
    class Solution {
    public:
        int findNthDigit(int n) {
            long num=0,start=1,i=1;
            if(n<10) return n;
            
            while(n>num+start*9*i){
                num+=start*9*i;
                i++;
                start*=10;
            }
            
            int target=n-num-1;
            num=start+target/i;
            int base=1;
            for(int j=i-1;j>target%i;j--) num/=10;
            return num%10;
        }
    };
    

Log in to reply
 

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