Categorygithub.com/szhou12/leetcode-goleetcode0973-K-Closest-Points-to-Origin
package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev

# README

973. K Closest Points to Origin

Solution idea:

Idea 1

  1. sort input array by distance
  2. output first k elements Time = $O(n\log n)$

Idea 2

Use a max-heap whose value considers the distance Keep inserting elements and pop the remained k elements Time = $O(n\log n)$