스파르타코딩클럽/활동 내용
[스파르타] 99클럽 2기 코테스터디 28일차 TIL / leet 1282
신선한 스타트
2024. 6. 16. 23:51
Leetcode: 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