일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 리얼 클래스
- 사이드
- Daily Challenge
- 영어원서읽기
- Problem Solving
- 개발자
- 30분
- 괜찮음
- 월간
- 3줄정리
- 파비최
- 화상영어
- 매일
- 뭐든
- realclass
- 링피트
- Writing
- FIT XR
- English
- 미드시청
- 10분
- 읽기
- 쓰릴오브파이트
- 만화도
- 스탭퍼
- 운동
- 프로젝트
- 잡생각
- 영어공부
- leetcode
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.09.11 Today's Challenge 본문
https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to/
Group the People Given the Group Size They Belong To - LeetCode
Can you solve this real interview question? Group the People Given the Group Size They Belong To - There are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1. You are given an integer
leetcode.com
해쉬 테이블을 활용해서 풀면 됨
class Solution:
def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:
groups, result = {}, []
for i, size in enumerate(groupSizes):
if size not in groups:
groups[size] = []
groups[size].append(i)
if len(groups[size]) == size:
result.append(groups[size])
groups[size] = []
return result
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.09.13 Today's Challenge (0) | 2023.09.13 |
---|---|
2023.09.12 Today's Challenge (0) | 2023.09.12 |
2023.09.10 Today's Challenge (0) | 2023.09.10 |
2023.09.09 Today's Challenge (0) | 2023.09.09 |
2023.09.08 Today's Challenge (0) | 2023.09.08 |
Comments