c++ easy to understand 0ms solution


  • 0
        int findNthDigit(int n) {
            int length=0;
            //find length
            for(int i=0;i<10;i++){
                if(n-(pow(10,i+1)-1-pow(10,i)+1)*(i+1)>0)
                    n=n-(pow(10,i+1)-1-pow(10,i)+1)*(i+1);
                else{
                    length=i+1;
                    break;
                }
            }
            n--;
            //find actually number
            int number=pow(10,length-1)+n/length;
            //return digit
            return (int)(number/pow(10,length-1-n%length))%10;
        }
    

Log in to reply
 

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