题解 | #数字序列中某一位的数字#
数字序列中某一位的数字
https://www.nowcoder.com/practice/29311ff7404d44e0b07077f4201418f5
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @return int整型
*/
function findNthDigit( n ) {
// write code here
let digitCount = 1
let left = 0
let right = 10
while (n > (right - left) * digitCount) {
n -= (right - left) * digitCount
left = right
right = right * 10
digitCount++
}
const number = Math.ceil(n / digitCount) + left
const rest = n % digitCount
return number.toString()[rest]
}
module.exports = {
findNthDigit : findNthDigit
};
