Розмір відео: 1280 X 720853 X 480640 X 360
Показувати елементи керування програвачем
Автоматичне відтворення
Автоповтор
why dont use hashset? if hashset size < n, false.
Yes. ArrayList also worked for this.
i think it fails if room is empty
but still logic was really good
BFS Solution: class Solution { public boolean canVisitAllRooms(List rooms) { Set visited = new HashSet(); Queue queue = new LinkedList(); queue.add(0); while(!queue.isEmpty()) { int room = queue.poll(); if(!visited.contains(room)) { visited.add(room); List keys = rooms.get(room); queue.addAll(keys); } } return visited.size() == rooms.size(); }}
Nice explanation!! keep it up !!
When i think you cant have worst explanations..there you are.
Awesome Explanation @Nick.
Thank you NICK!
Amazing stuff bruh!!
I am wondering how keys.add worked with stack....it's .push with stack
both works. You can refer to java docs , will get clear picture for Stack class.
Nice one
Awesome 👏
Best solution
better use hash map kind of
Its also called BFS Traversal
Done
This is a BFS search on a graph
Its actually dfs not bfs
bfs uses queue. dfs uses stack
👏❤️
He is soo cutee
why do all these videos do it in java
why dont use hashset? if hashset size < n, false.
Yes. ArrayList also worked for this.
i think it fails if room is empty
but still logic was really good
BFS Solution:
class Solution {
public boolean canVisitAllRooms(List rooms) {
Set visited = new HashSet();
Queue queue = new LinkedList();
queue.add(0);
while(!queue.isEmpty()) {
int room = queue.poll();
if(!visited.contains(room)) {
visited.add(room);
List keys = rooms.get(room);
queue.addAll(keys);
}
}
return visited.size() == rooms.size();
}
}
Nice explanation!! keep it up !!
When i think you cant have worst explanations..there you are.
Awesome Explanation @Nick.
Thank you NICK!
Amazing stuff bruh!!
I am wondering how keys.add worked with stack....it's .push with stack
both works. You can refer to java docs , will get clear picture for Stack class.
Nice one
Awesome 👏
Best solution
better use hash map kind of
Its also called BFS Traversal
Done
This is a BFS search on a graph
Its actually dfs not bfs
bfs uses queue. dfs uses stack
👏❤️
He is soo cutee
why do all these videos do it in java