Skip to content

Commit

Permalink
Update and rename 378. Kth Smallest Element in a Sorted Matrix.cpp to…
Browse files Browse the repository at this point in the history
… 378. Kth Smallest Element in a Sorted Matrix.md
  • Loading branch information
keineahnung2345 authored Apr 18, 2022
1 parent e65fb93 commit 80fe648
Showing 1 changed file with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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<vector<int>>& matrix, int k) {
Expand All @@ -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;
Expand Down Expand Up @@ -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<vector<int>>& matrix, int k) {
Expand Down Expand Up @@ -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<int>& nums, vector<int>& result, vector<vector<int>>& results){
Expand Down Expand Up @@ -173,3 +197,4 @@ class Solution {
return results;
}
};
```

0 comments on commit 80fe648

Please sign in to comment.