| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
Tags
- 월간
- 3줄정리
- Daily Challenge
- 10분
- 파비최
- realclass
- 영어공부
- Writing
- 스탭퍼
- 읽기
- 화상영어
- 쓰릴오브파이트
- English
- 프로젝트
- 뭐든
- 리얼 클래스
- Problem Solving
- 괜찮음
- leetcode
- 개발자
- 링피트
- 잡생각
- 매일
- 30분
- 미드시청
- 운동
- FIT XR
- 영어원서읽기
- 사이드
- 만화도
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/keys-and-rooms/
Keys and Rooms - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
오랫만에 내가 풀어봄 ㅋㅋ
bfs는 dfs에 비해 쉬운듯.. 아니면 내 실력이 늘었거나? (아니겠지만 =_=)
사실 어제 풀었던 문제와 꽤 유사해서 특별히 아이디어를 더할 건 없었음. (visited를 사용하는 부분)
class Solution:
def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
l = len(rooms)
visited = [True] + [False] * (l-1)
qu = deque()
for r in rooms[0]:
qu.append(r)
while qu:
room = qu.popleft()
if visited[room]:
continue
visited[room] = True
for r in rooms[room]:
qu.append(r)
for v in visited:
if not v:
return False
return True반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| Today's Challenge (0) | 2022.12.22 |
|---|---|
| Today's Challenge (0) | 2022.12.21 |
| Today's Challenge (0) | 2022.12.19 |
| Today's Challenge (0) | 2022.12.18 |
| Today's Challenge (0) | 2022.12.17 |
Comments