선발대

[스파르타] 99클럽 2기 코테스터디 28일차 TIL / leet 1282 본문

스파르타코딩클럽/활동 내용

[스파르타] 99클럽 2기 코테스터디 28일차 TIL / leet 1282

신선한 스타트 2024. 6. 16. 23:51

Leetcode: 1282. Group the People Given the Group Size They Belong To  (링크)

 

1282. Group the People Given the Group Size They Belong To

 

 

 

class Solution:
    def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:
        res = []
        hm = defaultdict(list)

        for person, groupSize in enumerate(groupSizes):
            if groupSize in hm and len(hm[groupSize]) == groupSize:
                res.append(hm[groupSize])
                hm[groupSize] = []
            hm[groupSize].append(person)

        for li in hm.values():
            if li: res.append(li)

        return res

오늘 미들러 풀이 끝!


참고한 풀이: https://www.youtube.com/watch?v=RrnhHjJmzj8

Comments