2078.两栋颜色不同且距离最远的房子

https://leetcode-cn.com/problems/two-furthest-houses-with-different-colors/

一、暴力

class Solution:
    def maxDistance(self, colors: List[int]) -> int:
        n = len(colors)
        res = 0
        for i in range(n):
            for j in range(i):
                if colors[i] != colors[j]:
                    res = max(res, i-j)
        return res

最后更新于