--- title: 841. Keys and Rooms tags: graph description: share source code. --- # 841. Keys and Rooms ```java= class Solution { public boolean canVisitAllRooms(List<List<Integer>> rooms) { Queue<Integer> q = new LinkedList<>(); q.offer(0); Set<Integer> visited = new HashSet<>(); while(!q.isEmpty()){ int key = q.poll(); if(visited.contains(key)){ continue; } visited.add(key); for(int m : rooms.get(key)){ q.offer(m); } } return visited.size() == rooms.size(); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up