L1 : 햄버거 만들기 Python

jhyunn·2023년 1월 12일
0

Programmers

목록 보기
9/69

L1 : 햄버거 만들기 Python

https://school.programmers.co.kr/learn/courses/30/lessons/133502

def solution(ingredient):
    temp = []
    cnt = 0
    for i in ingredient:
        temp.append(i)
        if temp[-4:] == [1, 2, 3, 1]:
            cnt+=1
            del temp[-4:]
    return cnt

빈 리스트를 생성해, 재료를 하나씩 넣는다. 그 리스트에서 가장 마지막의 4개 재료만을 비교하며 loop

profile
https://github.com/Sungjeonghyun

0개의 댓글