[LeetCode] 2260. Minimum Consecutive Cards to Pick Up

김민우·2022년 12월 18일
0

알고리즘

목록 보기
88/189

- Problem

2260. Minimum Consecutive Cards to Pick Up


- 내 풀이

class Solution:
    def minimumCardPickup(self, cards: List[int]) -> int:
        card_dict, answer = dict(), float('inf')

        for i, v in enumerate(cards):
            if v in card_dict:
                answer = min(i-card_dict[v] + 1, answer)
            card_dict[v] = i

        return -1 if answer == float('inf') else answer

- 결과

profile
Pay it forward.

0개의 댓글