diff --git a/leetcode/p378_kth_smallest_in_matrix.cpp b/leetcode/p378_kth_smallest_in_matrix.cpp new file mode 100644 index 0000000..368a589 --- /dev/null +++ b/leetcode/p378_kth_smallest_in_matrix.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + int kthSmallest(vector>& matrix, int k) { + std::priority_queue my_pq; + int size = matrix.size(); + for(int i=0;ik){ + my_pq.pop(); + } + } + } + // when we get out of the above nested loops, we know the priority queue stores the k smallest elements, and at the top is the largest element among them. + return my_pq.top(); + } +};