Skip to content

Commit e82df41

Browse files
authored
Create two-furthest-houses-with-different-colors.py
1 parent 3c2d84b commit e82df41

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxDistance(self, colors):
6+
"""
7+
:type colors: List[int]
8+
:rtype: int
9+
"""
10+
result = 0
11+
for i, x in enumerate(colors):
12+
if x != colors[0]:
13+
result = max(result, i)
14+
if x != colors[-1]:
15+
result = max(result, len(colors)-1-i)
16+
return result
17+

0 commit comments

Comments
 (0)