- Naive sort
Sort the whole matrix and find the kth.
- Merge rows (or columns)
Merge the rows and find the kth.
O(k logn)ActuallyI think it's
O(n^2 logn)since k=O(n^2)
If k is guaranteed to be small, that the last one is definitely better. However In my opinion, generally the second solution is better. Do I understand it correctly?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.