[LeetCode][440. K-th Smallest in Lexicographical Order]

By Long Luo

This article is the solution of Problem 440. K-th Smallest in Lexicographical Order.

Brute Force

1
2
3
4
5
6
7
8
9
10
public int findKthNumber(int n, int k) {
String[] numStrs = new String[n];
for (int i = 1; i <= n; i++) {
numStrs[i - 1] = "" + i;
}

Arrays.sort(numStrs);

return Integer.parseInt(numStrs[k - 1]);
}

Analysis

  • Time Complexity: \(O(nlogn)\).
  • Space Complexity: \(O(n)\).

1
2



All suggestions are welcome. If you have any query or suggestion please comment below. Please upvote👍 if you like💗 it. Thank you:-)

Explore More Leetcode Solutions. 😉😃💗