-
월간 코드 챌린지 시즌1 스타수열코딩 테스트/Level 3 2021. 9. 6. 19:55반응형
https://programmers.co.kr/learn/courses/30/lessons/70130
파이썬
from collections import Counter def solution(array): if len(array) == 1: return 0 count = Counter(array) answer = -1 for key in count: if count[key] * 2 < answer: continue index, length = 0, 0 max_key = key while index < len(array) - 1: if (array[index] != max_key and array[index + 1] != max_key) or array[index] == array[index + 1]: index += 1 continue length += 2 index += 2 answer = max(answer, length) return answer
반응형