1
class Solution:
2
def maxDistance(self, colors: List[int]) -> int:
3
# first pass
4
l, r = 0, len(colors) - 1
5
dist = 0
6

7
while r > l:
8
if colors[r] != colors[l]:
9
dist = r - l
10
# slight performance increase, break out if you find it
11
# because it can't get bigger than this
12
break
13
r -= 1
14

15
# second pass, backwards
16
l, r = 0, len(colors) - 1
17
while r > l:
18
if colors[r] != colors[l]:
19
dist = max(dist, r - l)
20
break
21
l += 1
22

23
return dist

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0