-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path973.py
More file actions
26 lines (23 loc) · 1.06 KB
/
973.py
File metadata and controls
26 lines (23 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
__________________________________________________________________________________________________
sample 676 ms submission
# from heapq import *
# class Solution:
# def kClosest(self, points: 'List[List[int]]', K: 'int') -> 'List[List[int]]':
# h = []
# for i in points:
# dis = i[0]**2 + i[1]**2
# heappush(h,(dis,i))
# res = []
# for i in range(K):
# res.append(heappop(h)[1])
# return res
class Solution:
def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]:
# pointsList = collections.Counter(points)
return sorted(points,key = lambda x:x[0]*x[0]+x[1]*x[1])[:K]
__________________________________________________________________________________________________
sample 16772 kb submission
class Solution:
def kClosest(self, points: List[List[int]], K: int) -> List[List[int]]:
return sorted(points, key=lambda e: e[0]**2+e[1]**2)[0:K]
__________________________________________________________________________________________________