728x90
320x100
def solution(input_string):
answer = ''
count = {}
answer_list = []
# {알파벳 : [알파벳이 있는 인덱스]}
for idx, alpha in enumerate(input_string):
if alpha not in count:
count[alpha] = [idx]
else:
count[alpha].append(idx)
for key, value in count.items():
if len(value) >= 2:
for i in range(len(value) - 1):
if abs(value[i]-value[i+1]) > 1:
answer_list.append(key)
break
if len(answer_list) == 0:
answer = "N"
else:
answer = ''.join(sorted(answer_list))
return answer
- 해당 알파벳에 해당되는 인덱스 번호를 딕셔너리 형태로 담아줌
- 인덱스 번호끼리의 거리가 1이상인 경우 연속되지 않는 알파벳이기 때문에 그 알파벳 리스트를 담아줌
- 그 알파벳 리스트를 string 형태로 변환
결국 제대로 못풀어서 다른 분 풀이 가지고 옴.....
728x90
320x100
'💻 하나씩 차곡차곡 > 프로그래머스 (Python)' 카테고리의 다른 글
[프로그래머스/Lv2/Python] 큰 수 만들기 (0) | 2024.01.23 |
---|---|
[프로그래머스/Lv2/Python] 구명보트 (0) | 2024.01.22 |
[프로그래머스/LV.1/Python] 체육복 (0) | 2024.01.17 |
[프로그래머스/Lv.2/Python] 올바른 괄호 (0) | 2024.01.16 |
[프로그래머스/Lv.1/Python] 기능개발 (0) | 2024.01.15 |