【done+找规律】剑指offer44:找到第 k 位数字

力扣,https://leetcode.cn/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/description/
数学找规律,参考链接:https://leetcode.cn/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/solutions/219252/mian-shi-ti-44-shu-zi-xu-lie-zhong-mou-yi-wei-de-6/

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

你可能感兴趣的:(剑指offer题目笔记,算法,LeetCode)