-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
29 lines (26 loc) · 942 Bytes
/
solution.py
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
27
28
29
class Solution(object):
def maxDistToClosest(self, seats):
"""
:type seats: List[int]
:rtype: int
"""
start = 0
end = 0
length = len(seats)
max_distance = 0
for i in range(len(seats)):
seat = seats[i]
if seat == 1:
if start == 0 or end == length - 1:
max_distance = max(max_distance, end - start + 1)
else:
max_distance = max(max_distance, (end - start + 1) / 2 + (end - start + 1) % 2)
if i + 1 < length:
start = end = i + 1
else:
end = i
if start == 0 or end == length - 1:
max_distance = max(max_distance, end - start + 1)
else:
max_distance = max(max_distance, (end - start + 1) / 2 + (end - start + 1) % 2)
return max_distance