[나의 풀이]
def solution(arr):
answer = []
for value in arr:
if answer[-1:] == [value]:
continue
answer.append(value)
return answer
[다른 풀이]
def no_continuous(s):
a = []
for i in s:
if a[-1:] == [i]: continue
a.append(i)
return a
def no_continuous(s):
return [s[i] for i in range(len(s)) if s[i] != s[i+1:i+2]]
def no_continuous(s):
a=[ v for i,v in enumerate(s) if s[i-1]!=s[i]]
return a
def no_continuous(s):
result = []
for c in s:
if (len(result) == 0) or (result[-1] != c):
result.append(c)
return result
'workSpace > ALGORITHM' 카테고리의 다른 글
[Python] x만큼 간격이 있는 n개의 숫자 (0) | 2020.12.20 |
---|---|
[Python] 가운데 글자 가져오기 (0) | 2020.12.20 |
[Python] 문자열 내 p와 y의 개수 (0) | 2020.12.20 |
[Python] 약수의 합 (0) | 2020.12.18 |
[Python] 서울에서 김서방 찾기 (0) | 2020.12.17 |