Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Find K Pairs with Smallest Sums with M pointers?

Правка en1, от nonme, 2023-06-27 16:36:37

Hello everyone! Today's LeetCode Daily problem is Find K Pairs with Smallest Sums.

Problem description

This problem is commonly solved with with priority queue. Here's a C++ solution for reference.

Solution with PQ

Many users — and me in particular — initially tried to solve this problem with two pointers — and failed. But is there a way to solve this without priority queue anyway? Using three or more pointers? If not, why? Can it be proved?
Thanks for your attention in advance.

Теги priority queue, leetcode, two pointers

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский nonme 2023-06-27 16:36:37 2629 Initial revision (published)