C++ Accepted

  • 0
        int findNthDigit(int n) {
            int num=n;
            int i=0;
            //Get which range will the Nth number
            //range 0: 1~9    (9 digits)
            //range 1: 10~99 (2*90 digits)
            //range 2: 100~999 (3*digits)
            int start=pow(10,i);//Range start e.g 10
            int index=(num-1)/(i+1); //get number index in the range e.g 0 
            int realnum=start+index;//get the real number which holds the Nth number e.g 10.
            int dindex=(num-1)%(i+1);//Get digit index with the real number e.g 1.
            return (int)(realnum/(pow(10,i-dindex)))%10; //get Nth number

Log in to reply

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