leetcode-面试题44-数字序列某位中的数字

题目描述:

 

 方法一:找规律

class Solution {
    public int findNthDigit(int n) {
        int digit = 1;
        long start = 1;
        long count = 9;
        while(n > count){
            n -= count;
            digit += 1;
            start *= 10;
            count = digit * start * 9;
        }
        long num = start + (n - 1) /digit;
        return Long.toString(num).charAt((n-1) % digit) - '0';
    }
}

 

posted @ 2020-05-17 12:56  oldby  阅读(136)  评论(0编辑  收藏  举报