1 回答

紅糖糍粑
TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊
function findKthNumber(n, k) {
let curr = 1;
k = k - 1;
while (k > 0) {
let steps = calSteps(n, curr, curr + 1);
if (steps <= k) {
curr += 1;
k -= steps;
} else {
curr *= 10;
k -= 1;
}
}
return curr;
}
function calSteps(n, n1, n2) {
let steps = 0;
while (n1 <= n) {
steps += Math.min(n + 1, n2) - n1;
n1 *= 10;
n2 *= 10
}
return steps;
}
添加回答
舉報(bào)
0/150
提交
取消