- μ°μ μμ ν κ³ λ €νμ§λ μκ³ λ΄κ° μκ°ν λ°©μμΌλ‘ νμλλ° 97νΌ λμλ€.
- μ νμλ€λ λ»μΌκΉ..?
Solution
from typing import List
class Solution:
def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]:
answer: List[List[int]] = []
for x, y in points:
# μ΄μ°¨νΌ 거리 λΉκ΅λκΉ λ£¨νΈλ μ κ²½μ°μ§ μμλ λ λ―
distance = (0 - x) ** 2 + (0 - y) ** 2
answer.append([distance, x, y])
answer.sort(key=lambda z: z[0])
answer = answer[:k]
for one in answer:
one.pop(0)
return answer
Reference
Leave a comment