diff --git a/378. Kth Smallest Element in a Sorted Matrix.cpp b/378. Kth Smallest Element in a Sorted Matrix.md similarity index 79% rename from 378. Kth Smallest Element in a Sorted Matrix.cpp rename to 378. Kth Smallest Element in a Sorted Matrix.md index 4976ce0..8782685 100644 --- a/378. Kth Smallest Element in a Sorted Matrix.cpp +++ b/378. Kth Smallest Element in a Sorted Matrix.md @@ -1,6 +1,13 @@ -//Priority queue -//Runtime: 84 ms, faster than 14.51% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. -//Memory Usage: 12.4 MB, less than 59.09% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. +# 378. Kth Smallest Element in a Sorted Matrix + +[leetcode - 378. Kth Smallest Element in a Sorted Matrix](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/) + +## Priority queue +Runtime: 84 ms, faster than 14.51% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. + +Memory Usage: 12.4 MB, less than 59.09% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. + +```cpp class Solution { public: int kthSmallest(vector>& matrix, int k) { @@ -21,11 +28,16 @@ class Solution { return pq.top(); } }; +``` -//Priority queue(optimized) -//https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/discuss/85173/Share-my-thoughts-and-Clean-Java-Code -//Runtime: 68 ms, faster than 27.19% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. -//Memory Usage: 14.2 MB, less than 9.09% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. +## Priority queue(optimized) +https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/discuss/85173/Share-my-thoughts-and-Clean-Java-Code + +Runtime: 68 ms, faster than 27.19% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. + +Memory Usage: 14.2 MB, less than 9.09% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. + +```cpp class Tuple{ public: int x; @@ -64,11 +76,18 @@ class Solution { return pq.top()->val; } }; +``` + -//Solution 2 : Binary Search in range -//https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/discuss/85173/Share-my-thoughts-and-Clean-Java-Code -//Runtime: 36 ms, faster than 94.39% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. -//Memory Usage: 11.1 MB, less than 100.00% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. +## Solution 2 : Binary Search in range + +https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/discuss/85173/Share-my-thoughts-and-Clean-Java-Code + +Runtime: 36 ms, faster than 94.39% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. + +Memory Usage: 11.1 MB, less than 100.00% of C++ online submissions for Kth Smallest Element in a Sorted Matrix. + +```cpp class Solution { public: int kthSmallest(vector>& matrix, int k) { @@ -105,11 +124,16 @@ class Solution { return lo; } }; +``` + +## findNSum, recursive, optimized +https://leetcode.com/problems/4sum/discuss/8545/Python-140ms-beats-100-and-works-for-N-sum-(Ngreater2) + +Runtime: 8 ms, faster than 98.35% of C++ online submissions for 4Sum. + +Memory Usage: 8.5 MB, less than 100.00% of C++ online submissions for 4Sum. -//findNSum, recursive, optimized -//https://leetcode.com/problems/4sum/discuss/8545/Python-140ms-beats-100-and-works-for-N-sum-(Ngreater2) -//Runtime: 8 ms, faster than 98.35% of C++ online submissions for 4Sum. -//Memory Usage: 8.5 MB, less than 100.00% of C++ online submissions for 4Sum. +```cpp class Solution { public: void findNSum(int l, int r, int target, int N, vector& nums, vector& result, vector>& results){ @@ -173,3 +197,4 @@ class Solution { return results; } }; +```