
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
History is littered with hundreds of conflicts over the future of a community, group, location or business that were "resolved" when one of the parties stepped ahead and destroyed what was there. With the original point of contention destroyed, the debates would fall to the wayside. Archive Team believes that by duplicated condemned data, the conversation and debate can continue, as well as the richness and insight gained by keeping the materials. Our projects have ranged in size from a single volunteer downloading the data to a small-but-critical site, to over 100 volunteers stepping forward to acquire terabytes of user-created data to save for future generations.
The main site for Archive Team is at archiveteam.org and contains up to the date information on various projects, manifestos, plans and walkthroughs.
This collection contains the output of many Archive Team projects, both ongoing and completed. Thanks to the generous providing of disk space by the Internet Archive, multi-terabyte datasets can be made available, as well as in use by the Wayback Machine, providing a path back to lost websites and work.
Our collection has grown to the point of having sub-collections for the type of data we acquire. If you are seeking to browse the contents of these collections, the Wayback Machine is the best first stop. Otherwise, you are free to dig into the stacks to see what you may find.
The Archive Team Panic Downloads are full pulldowns of currently extant websites, meant to serve as emergency backups for needed sites that are in danger of closing, or which will be missed dearly if suddenly lost due to hard drive crashes or server failures.
There are
N
rooms and you start in room0
. Each room has a distinct number in0, 1, 2, ..., N-1
, and each room may have some keys to access the next room.Formally, each room
i
has a list of keysrooms[i]
, and each keyrooms[i][j]
is an integer in[0, 1, ..., N-1]
whereN = rooms.length
. A keyrooms[i][j] = v
opens the room with numberv
.Initially, all the rooms start locked (except for room
0
).You can walk back and forth between rooms freely.
Return
true
if and only if you can enter every room.Example 1:
Example 2:
Note:
1 <= rooms.length <= 1000
0 <= rooms[i].length <= 1000
3000
.这道题给了我们一些房间,房间里有一些钥匙,用钥匙可以打开对应的房间,说是起始时在房间0,问最终是否可以打开所有的房间。这不由得让博主想起了惊悚片《万能钥匙》,还真是头皮发麻啊。赶紧扯回来,这是一道典型的有向图的遍历的题,邻接链表都已经建立好了,这里直接遍历就好了,这里先用 BFS 来遍历。使用一个 HashSet 来记录访问过的房间,先把0放进去,然后使用 queue 来辅助遍历,同样将0放入。之后进行典型的 BFS 遍历,取出队首的房间,然后遍历其中的所有钥匙,若该钥匙对应的房间已经遍历过了,直接跳过,否则就将钥匙加入 HashSet。此时看若 HashSet 中的钥匙数已经等于房间总数了,直接返回 true,因为这表示所有房间已经访问过了,否则就将钥匙加入队列继续遍历。最后遍历结束后,就看 HashSet 中的钥匙数是否和房间总数相等即可,参见代码如下:
解法一:
我们也可以使用递归的解法来做,还是使用 HashSet 来记录访问过的房间,递归函数还需要传进当前的房间,还有 HashSet,首先将当前房间加入 HashSet,然后遍历此房间中的所有钥匙,如果其对应的房间没有访问过,则调用递归函数,参见代码如下:
解法二:
Github 同步地址:
#841
参考资料:
https://leetcode.com/problems/keys-and-rooms/
https://leetcode.com/problems/keys-and-rooms/discuss/133944/Java-8-lines
https://leetcode.com/problems/keys-and-rooms/discuss/133855/Straight-Forward
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: