백준 27159번: 노 땡스! #Python

ColorlessDia·2024년 2월 16일

algorithm/baekjoon

목록 보기
87/808
N = int(input())
card_list = list(map(int, input().split()))

group_list = []
temp = []

for card in card_list:
    if len(temp) == 0:
        temp.append(card)
    else:
        if card - temp[-1] == 1:
            temp.append(card)
        else:
            group_list.append(temp)
            temp = [card]

group_list.append(temp)

score = 0

for group in group_list:
    score += group[0]

print(score)

0개의 댓글