Skip to content

Instantly share code, notes, and snippets.

@nags0x
Created June 9, 2025 10:08
Show Gist options
  • Select an option

  • Save nags0x/e23ebde9ee09b9bdff8f0a4fea7295a2 to your computer and use it in GitHub Desktop.

Select an option

Save nags0x/e23ebde9ee09b9bdff8f0a4fea7295a2 to your computer and use it in GitHub Desktop.
#440
class Solution {
public:
int findKthNumber(int n, int k) {
long long node = 1;
for (int i = 1; i <= k; i++) {
if (i == k) {
return node;
}
if (node * 10 <= n) {
node *= 10;
} else {
while ((node % 10 == 9 || node + 1 > n) && node > 0) {
node /= 10;
}
node++;
}
}
return -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment