-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path849.py
30 lines (29 loc) · 829 Bytes
/
849.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
30
#coding=utf-8
class Solution:
def maxDistToClosest(self, seats):
"""
:type seats: List[int]
:rtype: int
"""
flag = False
maxdistance = 0
left = 0
for index, seat in enumerate(seats):
if flag:
if seat == 1:
maxdistance = max(maxdistance, (index-left)//2)
left = index
else:
continue
else:
if seat == 1:
flag = True
maxdistance = max(maxdistance, index)
left = index
else:
continue
maxdistance = max(maxdistance, index-left)
return maxdistance
s = Solution()
res = s.maxDistToClosest([1, 0, 0, 0, 1, 0, 1])
print(res)