Share my c++ solution


  • 0
    W
    class Solution {
    public:
        int findNthDigit(int n) {
              int base = 1;
              int level = 1;
              
              if (n == 1)
                return 1;
            
              while (n>0) {
                  if ((((long long)(base))*9*level) >=(long long)(n))
                    break;
                  
                  n = n - maixum;
                  
                  base = base*10;
                  level++;
              }
              
              int number = base + (n-1)/level;
              int bit = level - 1 - (n-1)%level;
              
              for (; bit > 0; bit--) {
                  number = number/10;
              }
              
              return number%10;
        }
    };
    

Log in to reply
 

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