1. 시간초과 - 50점 코드
def detection(data):
burger = [1, 2, 3, 1]
if len(data) < 4:
return -1
for i in range(len(data) - 3):
if data[i:i+4] == burger:
return data[:i] + data[i+4:]
return -1
def solution(ingredient):
answer = 0
while True:
ingredient = detection(ingredient)
if ingredient == -1:
break
answer += 1
return answer
2. del을 이용한 풀이
def solution(ingredient):
data = []
answer = 0
for i in ingredient:
data.append(i)
if data[-4:] == [1, 2, 3, 1]:
answer += 1
del data[-4:]
return answer
'코딩 테스트 (Coding Test)' 카테고리의 다른 글
[프로그래머스] 콜라 문제 (0) | 2023.01.09 |
---|---|
[프로그래머스] - 옹알이 (2) (0) | 2023.01.09 |
[프로그래머스] 푸드 파이트 대회 (0) | 2023.01.05 |
[프로그래머스] 과일 장수 (0) | 2023.01.05 |
[프로그래머스] 기사단원의 무기 (0) | 2023.01.05 |