File tree 1 file changed +12
-13
lines changed
scripts/algorithms/H/Heaters
1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change
1
+ # Runtime: 766 ms (Top 22.98%) | Memory: 17.7 MB (Top 39.36%)
1
2
class Solution :
2
3
def findRadius (self , houses : List [int ], heaters : List [int ]) -> int :
3
4
"""
4
-
5
+
5
6
"""
6
-
7
-
7
+
8
8
houses .sort ()
9
9
heaters .sort ()
10
-
11
-
10
+
12
11
max_radius = - inf
13
-
14
- for house in houses :
12
+
13
+ for house in houses :
15
14
i = bisect_left (heaters , house )
16
-
15
+
17
16
if i == len (heaters ):
18
17
max_radius = max (max_radius , house - heaters [- 1 ])
19
- elif i == 0 :
20
- max_radius = max (max_radius , heaters [i ] - house )
18
+ elif i == 0 :
19
+ max_radius = max (max_radius , heaters [i ] - house )
21
20
else :
22
21
curr = heaters [i ]
23
22
prev = heaters [i - 1 ]
24
23
max_radius = max (max_radius ,min (abs (house - curr ), abs (house - prev )))
25
-
24
+
26
25
return max_radius
27
-
28
- # O(NLOGN)
26
+
27
+ # O(NLOGN)
You can’t perform that action at this time.
0 commit comments