class Solution {
public int findKthNumber(int n, int k) {
int ans = 1;
while(k>1){
int count = dfs(ans,n);
//求出子树的数量和K比较,若大于k则在子树中找,否则在循环下一个节点
if(count<k){
ans++;
k-=count;
}else{
ans*=10;
k--;
}
}
return ans;
}
//计算子树中的总数
public int dfs(long ans,long n){
int tem = 0;
long left = n;
long right = n;
while(left<=right){
tem += Math.min(right,n) - left +1;
left*=10;
right=right*10+9;
}
return tem;
}
}