[Algorithm] 11 week(3.21 ~ 3.27) 1/3

Dev_min·2022년 3월 21일
0

algorithm

목록 보기
35/157

2078. Two Furthest Houses With Different Colors

var maxDistance = function(colors) {
    let result = -1;
    
    for (let i = 0; i < colors.length; i++) {
        for (let j = colors.length-1; j > i ; j--) {
            if (colors[j] !== colors[i]) {
                result = Math.max(result, j - i);
            }
        }
    }
    return result;
};
profile
TIL record

0개의 댓글