Skip to content

Commit 26f13cc

Browse files
committed
Create README - LeetHub
1 parent f3e9d7b commit 26f13cc

File tree

1 file changed

+71
-0
lines changed
  • 2061-number-of-spaces-cleaning-robot-cleaned

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<h2><a href="https://leetcode.com/problems/number-of-spaces-cleaning-robot-cleaned/">2061. Number of Spaces Cleaning Robot Cleaned</a></h2><h3>Medium</h3><hr><div><p>A room is represented by a <strong>0-indexed</strong> 2D binary matrix <code>room</code> where a <code>0</code> represents an <strong>empty</strong> space and a <code>1</code> represents a space with an <strong>object</strong>. The top left corner of the room will be empty in all test cases.</p>
2+
3+
<p>A cleaning robot starts at the top left corner of the room and is facing right. The robot will continue heading straight until it reaches the edge of the room or it hits an object, after which it will turn 90 degrees <strong>clockwise</strong> and repeat this process. The starting space and all spaces that the robot visits are <strong>cleaned</strong> by it.</p>
4+
5+
<p>Return <em>the number of <strong>clean</strong> spaces in the room if the robot runs indefinetely.</em></p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
<img src="https://assets.leetcode.com/uploads/2021/11/01/image-20211101204703-1.png" style="width: 250px; height: 242px;">
10+
<p>&nbsp;</p>
11+
12+
<div class="example-block">
13+
<p><strong>Input:</strong> <span class="example-io">room = [[0,0,0],[1,1,0],[0,0,0]]</span></p>
14+
15+
<p><strong>Output:</strong> <span class="example-io">7</span></p>
16+
17+
<p><strong>Explanation:</strong></p>
18+
19+
<ol>
20+
<li>​​​​​​​The robot cleans the spaces at (0, 0), (0, 1), and (0, 2).</li>
21+
<li>The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces down.</li>
22+
<li>The robot cleans the spaces at (1, 2), and (2, 2).</li>
23+
<li>The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces left.</li>
24+
<li>The robot cleans the spaces at (2, 1), and (2, 0).</li>
25+
<li>The robot has cleaned all 7 empty spaces, so return 7.</li>
26+
</ol>
27+
</div>
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
<img src="https://assets.leetcode.com/uploads/2021/11/01/image-20211101204736-2.png" style="width: 250px; height: 245px;">
31+
<p>&nbsp;</p>
32+
33+
<div class="example-block">
34+
<p><strong>Input:</strong> <span class="example-io">room = [[0,1,0],[1,0,0],[0,0,0]]</span></p>
35+
36+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
37+
38+
<p><strong>Explanation:</strong></p>
39+
40+
<ol>
41+
<li>The robot cleans the space at (0, 0).</li>
42+
<li>The robot hits an object, so it turns 90 degrees clockwise and now faces down.</li>
43+
<li>The robot hits an object, so it turns 90 degrees clockwise and now faces left.</li>
44+
<li>The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces up.</li>
45+
<li>The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces right.</li>
46+
<li>The robot is back at its starting position.</li>
47+
<li>The robot has cleaned 1 space, so return 1.</li>
48+
</ol>
49+
</div>
50+
51+
<p><strong class="example">Example 3:</strong></p>
52+
53+
<div class="example-block">
54+
<p><strong>Input:</strong> <span class="example-io">room = [[0,0,0],[0,0,0],[0,0,0]]</span></p>
55+
56+
<p><strong>Output:</strong> <span class="example-io">8</span>​​​​​​​</p>
57+
58+
<p>&nbsp;</p>
59+
</div>
60+
61+
<p>&nbsp;</p>
62+
<p><strong>Constraints:</strong></p>
63+
64+
<ul>
65+
<li><code>m == room.length</code></li>
66+
<li><code>n == room[r].length</code></li>
67+
<li><code>1 &lt;= m, n &lt;= 300</code></li>
68+
<li><code>room[r][c]</code> is either <code>0</code> or <code>1</code>.</li>
69+
<li><code>room[0][0] == 0</code></li>
70+
</ul>
71+
</div>

0 commit comments

Comments
 (0)