https://school.programmers.co.kr/learn/courses/30/lessons/12906
내풀이
길이 0일 경우를 따로 처리해주지 않으면 index가 초과해버리길래
이렇게 분화해주었지만
def solution(arr):
answer = []
for i in arr:
if len(answer) == 0:
answer.append(i)
elif answer[-1] != i:
answer.append(i)
return answer
타풀이
에서 기깔나게 리스트 슬라이싱 해서 리스트로 비교하여 분화 없이 해결하였다
def solution(s):
a = []
for i in s:
if a[-1:] == [i]: continue
a.append(i)
return a
+ 이렇게 해보니 인덱스 초과 없이 빈리스트로 반환하더라
a = []
a = a[-2:]
print(a)
#[]
'코테 공부 > python' 카테고리의 다른 글
[백준] #11403 Python 세미? 플로이드 워셜 (2) | 2023.06.30 |
---|---|
[백준] #1260 Python DFS와 BFS (1) | 2023.06.29 |
[백준] #2583 Python 영역구하기 -bfs (0) | 2023.06.28 |
Python DFS BFS (0) | 2023.06.21 |
Python 자료구조 stack, que (0) | 2023.06.20 |