- ์ฐ์ ์์ ํ ๊ณ ๋ คํ์ง๋ ์๊ณ ๋ด๊ฐ ์๊ฐํ ๋ฐฉ์์ผ๋ก ํ์๋๋ฐ 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