K Closest Points to Origin | LeetCode 973 | C++, Java, Python
HTML-код
- Опубликовано: 8 окт 2024
- LeetCode Solutions: • LeetCode Solutions | L...
June LeetCoding Challenge: • Playlist
May LeetCoding Challenge: • Playlist
*** Best Books For Data Structures & Algorithms for Interviews:*********
1. Cracking the Coding Interview: amzn.to/2WeO3eO
2. Cracking the Coding Interview Paperback: amzn.to/3aSSe3Q
3. Coding Interview Questions - Narasimha Karumanchi: amzn.to/3cYqjkV
4. Data Structures and Algorithms Made Easy - N. Karumanchi: amzn.to/2U8FrDt
5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: amzn.to/2U0qZgY
6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: amzn.to/2Wdp8rZ
*****************************************************************************
May LeetCoding Challenge | Problem 30 | K Closest Points to Origin | 30 May,
Facebook Coding Interview question,
google coding interview question,
leetcode,
K Closest Points to Origin,
K Closest Points to Origin c++,
K Closest Points to Origin Java,
K Closest Points to Origin python,
K Closest Points to Origin solution,
973. K Closest Points to Origin,
Max Heap,
priority queue,
#Facebook #CodingInterview #LeetCode #MayLeetCodingChallenge #Google #Amazon #MaxHeap
I was just struggling with this problem and you have made it look like a piece of cake. Thank you very much! :)
Glad it helped.
The for loop can be simplified as follows:
for(int[] temp: points){
pq.add(new Point(temp));
if(pq.size() > K){
pq.remove();
}
}
legendary
Haha. Thanks
Can't we just take priority queue with min heap and just the pop the element k times
Sir, why do we need to define the comparison method in a structure?