Created
June 9, 2025 10:08
-
-
Save nags0x/e23ebde9ee09b9bdff8f0a4fea7295a2 to your computer and use it in GitHub Desktop.
#440
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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