849. Maximize Distance to Closest Person
unknown
python
4 years ago
404 B
7
Indexable
from math import *
class Solution:
def maxDistToClosest(self, seats: List[int]) -> int:
ans, zero = -1, seats.index(1) #for leading 0's they are counted twice
for i in seats:
if i:
ans = max(ans, ceil(zero/2))
zero = 0
else:
zero += 1
return max(ans, zero) #in case trailing 0's present
Editor is loading...