Skip to content

Commit d2d23e8

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Update 841. Keys and Rooms.py
Co-Authored-By: Antim-IWP <[email protected]> Co-Authored-By: Shiwangi Srivastava <[email protected]>
1 parent de42af6 commit d2d23e8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
1+
class Solution:
2+
def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
3+
def dfs(i: int):
4+
if i in vis:
5+
return
6+
vis.add(i)
7+
for j in rooms[i]:
8+
dfs(j)
9+
10+
vis = set()
11+
dfs(0)
12+
return len(vis) == len(rooms)

0 commit comments

Comments
 (0)