Skip to content

Commit 59370dc

Browse files
committed
Create README - LeetHub
source:1a6d0b4e0d5287c5f1bc1552f897176066de73cf
1 parent 0c97ea7 commit 59370dc

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

  • 공예영/8주차/0841-keys-and-rooms
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2><a href="https://leetcode.com/problems/keys-and-rooms">871. Keys and Rooms</a></h2><h3>Medium</h3><hr><p>There are <code>n</code> rooms labeled from <code>0</code> to <code>n - 1</code>&nbsp;and all the rooms are locked except for room <code>0</code>. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.</p>
2+
3+
<p>When you visit a room, you may find a set of <strong>distinct keys</strong> in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms.</p>
4+
5+
<p>Given an array <code>rooms</code> where <code>rooms[i]</code> is the set of keys that you can obtain if you visited room <code>i</code>, return <code>true</code> <em>if you can visit <strong>all</strong> the rooms, or</em> <code>false</code> <em>otherwise</em>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> rooms = [[1],[2],[3],[]]
12+
<strong>Output:</strong> true
13+
<strong>Explanation:</strong>
14+
We visit room 0 and pick up key 1.
15+
We then visit room 1 and pick up key 2.
16+
We then visit room 2 and pick up key 3.
17+
We then visit room 3.
18+
Since we were able to visit every room, we return true.
19+
</pre>
20+
21+
<p><strong class="example">Example 2:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> rooms = [[1,3],[3,0,1],[2],[0]]
25+
<strong>Output:</strong> false
26+
<strong>Explanation:</strong> We can not enter room number 2 since the only key that unlocks it is in that room.
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li><code>n == rooms.length</code></li>
34+
<li><code>2 &lt;= n &lt;= 1000</code></li>
35+
<li><code>0 &lt;= rooms[i].length &lt;= 1000</code></li>
36+
<li><code>1 &lt;= sum(rooms[i].length) &lt;= 3000</code></li>
37+
<li><code>0 &lt;= rooms[i][j] &lt; n</code></li>
38+
<li>All the values of <code>rooms[i]</code> are <strong>unique</strong>.</li>
39+
</ul>

0 commit comments

Comments
 (0)