BiruLyu
8/22/2017 - 6:08 PM

400. Nth Digit(#).java

/*Check the same-length ranges 1-9, 10-99, 100-999, 1000-9999, etc.*/
class Solution {
    public int findNthDigit(int n) {
        n -= 1;
        int digits = 1, first = 1;
        while (n / 9 / first / digits >= 1) {
            n -= 9 * first * digits;
            digits++;
            first *= 10;
        }
        return (first + n/digits + "").charAt(n%digits) - '0';
    }
}