2078. Two Furthest Houses With Different Colors

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2078

class Solution:
    def maxDistance(self, colors: List[int]) -> int:
        n = len(colors)
        if colors[0] != colors[-1]:
            return n - 1
        i, j = 1, n - 2
        while colors[i] == colors[0]:
            i += 1
        while colors[j] == colors[0]:
            j -= 1
        return max(n - i - 1, j)