package leetcode;

/**
 * https://leetcode.com/problems/nth-digit/
 */
public class Problem400 {
    public int findNthDigit(int n) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem400 prob = new Problem400();
        System.out.println(prob.findNthDigit(3)); // 3
        System.out.println(prob.findNthDigit(11)); // 0
        System.out.println(prob.findNthDigit(15)); // 2
        System.out.println(prob.findNthDigit(17)); // 3
    }
}

@@ -12,16 +12,68 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -191,82 +191,278 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args
+List%3CRange%3E ranges = new ArrayList%3C%3E();%0A        long from = 1;%0A        long to = 9;%0A        long fromSeq = from;%0A        long toSeq = 9;%0A        int multiplier = 1;%0A        ranges.add(new Range(from, to, fromSeq, toSeq, multiplier));%0A        for (int i = 1; i %3C= 10; i++
 ) %7B%0A
@@ -473,266 +473,1136 @@
     
+   
-Problem400 prob = new Problem400();%0A        System.out.println(prob.findNthDigit(3)); // 3%0A        System.out.println(prob.findNthDigit(11)); //
+ fromSeq = toSeq + 1;%0A            from *= 10;%0A            to = (to * 10) + 9;%0A            multiplier = (i + 1);%0A            toSeq += ((to - from + 1) * multiplier);%0A            ranges.add(new Range(from, to, fromSeq, toSeq, multiplier));%0A        %7D%0A%0A        for (Range range : ranges) %7B%0A            if (range.fromSeq %3C= n && n %3C= range.toSeq) %7B%0A                long val = range.from + ((n - range.fromSeq) / range.multiplier);%0A                int mod = (int) (n - range.fromSeq) %25 range.multiplier;%0A                String str = Long.toString(val);%0A                return Integer.parseInt(%22%22 + str.charAt(mod));%0A            %7D%0A        %7D%0A        return
  0
+;
 %0A    
+%7D%0A%0A
     
-System.out.println(prob.findNthDigit(15)); // 2%0A        System.out.println(prob.findNthDigit(17)); // 3
+private static class Range %7B%0A        private final long from;%0A        private final long to;%0A        private final long fromSeq;%0A        private final long toSeq;%0A        private final int multiplier;%0A%0A        public Range(long from, long to, long fromSeq, long toSeq, int multiplier) %7B%0A            this.from = from;%0A            this.to = to;%0A            this.fromSeq = fromSeq;%0A            this.toSeq = toSeq;%0A            this.multiplier = multiplier;%0A        %7D
 %0A   

Solve problem 400