class Solution(object): def maxDistToClosest(self, seats): """ :type seats: List[int] :rtype: int """ m=0 i=0 j=0 if seats[0] == 0: j += 1 while seats[j] == 0: j += 1 m = max(m, j) i = j + 1 if i == len(seats): return m while j<len(seats) and i<len(seats): if seats[i]==1: i+=1 if i==len(seats): return m else: j=i while seats[j]==0 and j<len(seats): j+=1 if j==len(seats): m=max(m,j-i) return m if j!=len(seats): m=max(m,(j-i+1)//2) i=j+1 else: m=max(m,j-i) return m return m
执行用时 :132 ms, 在所有 python 提交中击败了81.56%的用户
内存消耗 :12.2 MB, 在所有 python 提交中击败了37.93%的用户
——2019.11.2