首刷用优先队列超时了
class Solution {
public:
int findKthNumber(int n, int k) {
int curr = 1;
k--;
while(k) {
int steps = getSteps(curr, n);
if(steps <= k) {
k -= steps;
curr++;
} else {
curr = curr*10;
k--;
}
}
return curr;
}
int getSteps(int curr, long n) {
int steps = 0;
long first = curr, last = curr;
while(first <= n) {
steps += min(last, n) - first + 1;
first = first * 10;
last = last * 10 + 9;
}
return steps;
}
};