首页 > 代码库 > nth-digit

nth-digit

https://leetcode.com/problems/nth-digit/public class Solution {    public int findNthDigit(int n) {        int k = 9;        int b = 1;        // 需要加上对b的限制        while (b < 9 && n > k*b) {            n -= k * b;            k *= 10;            b ++;        }        int rank = (n - 1) / b;        int app = (n - 1) % b;        int num = (int)Math.pow(10, b-1) + rank;        for (int i=b-1; i>app; i--) {            num /= 10;        }        return num % 10;    }}

 

nth-digit