# 【Python】【难度：简单】Leetcode 849. 到最近的人的最大距离

1 <= seats.length <= 20000
seats 中只含有 0 和 1，至少有一个 0，且至少有一个 1。

class Solution(object):
def maxDistToClosest(self, seats):
"""
:type seats: List[int]
:rtype: int
"""
index=-1
for i in range(len(seats)):
if seats[i]==0:
if 1 in seats[:i] and 1 in seats[i+1:]:
var=min(i-(len(seats[:i])-seats[:i][::-1].index(1)-1),seats[i+1:].index(1)+1)
if 1 in seats[:i] and 1 not in seats[i+1:]:
var=i-(len(seats[:i])-seats[:i][::-1].index(1)-1)
if 1 not in seats[:i] and 1 in seats[i + 1:]:
var=seats[i+1:].index(1)+1
if index<var:
index=var
return index

10-13 17

07-08 113

01-07 151

10-04 78

05-11 39

08-19 220

05-07 27

03-24 42

05-03 18

05-17 34

10-06 10

05-21 30

05-21 11

06-15 260

05-12 25

08-23 48

01-02 53

10-11 3

05-03 24

04-14 58万+

03-13 14万+

03-04 13万+

03-05 5715

03-08 4万+

03-08 7万+

03-10 12万+

03-12 11万+

03-13 11万+

03-14 1万+

03-18 5432

03-18 8720

03-19 3万+

03-19 8万+

03-20 7484

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-29 21万+

03-29 1万+

03-29 10万+

03-30 16万+

05-28 5159

05-28 1万+

04-02 4万+

04-03 3077

04-06 7万+

04-07 5万+

04-09 8万+

04-09 2万+

05-17 7434

04-10 2477

04-11 3万+

04-15 5万+

04-18 4万+

04-20 4万+

04-24 3万+

04-29 5834

04-29 5693

04-30 4582

04-30 8909

04-30 8423

05-16 5万+

05-08 4万+

05-11 3万+

05-12 1万+

05-13 435

05-14 5663

05-14 1503

05-16 1万+

05-20 517

05-18 7656

05-27 560

05-18 2959

05-19 9838

05-21 5642

05-21 5647

05-25 3403

#### 前端很容易遇到的一个大坑

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客