Skip to content

Latest commit

 

History

History
 
 

973.K-Closest-Points-to-Origin

973.K-Closest-Points-to-Origin

解法1:优先队列

构造一个关于距离的大顶堆。将各个点逐个放入,一旦PQ的元素个数超过K个就弹出队首元素。这样最终留下来的就是K个距离最小的。时间复杂度 NlogK.

解法2:快速选择

QucikSelect的模板题,时间复杂度的期望是o(N).