Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca02ade

Browse files
committed
Create README - LeetHub
1 parent 8891cf6 commit ca02ade

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎0305-number-of-islands-ii/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<h2><a href="https://leetcode.com/problems/number-of-islands-ii/">305. Number of Islands II</a></h2><h3>Hard</h3><hr><div><p>You are given an empty 2D binary grid <code>grid</code> of size <code>m x n</code>. The grid represents a map where <code>0</code>'s represent water and <code>1</code>'s represent land. Initially, all the cells of <code>grid</code> are water cells (i.e., all the cells are <code>0</code>'s).</p>
2+
3+
<p>We may perform an add land operation which turns the water at position into a land. You are given an array <code>positions</code> where <code>positions[i] = [r<sub>i</sub>, c<sub>i</sub>]</code> is the position <code>(r<sub>i</sub>, c<sub>i</sub>)</code> at which we should operate the <code>i<sup>th</sup></code> operation.</p>
4+
5+
<p>Return <em>an array of integers</em> <code>answer</code> <em>where</em> <code>answer[i]</code> <em>is the number of islands after turning the cell</em> <code>(r<sub>i</sub>, c<sub>i</sub>)</code> <em>into a land</em>.</p>
6+
7+
<p>An <strong>island</strong> is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/10/tmp-grid.jpg" style="width: 500px; height: 294px;">
12+
<pre><strong>Input:</strong> m = 3, n = 3, positions = [[0,0],[0,1],[1,2],[2,1]]
13+
<strong>Output:</strong> [1,1,2,3]
14+
<strong>Explanation:</strong>
15+
Initially, the 2d grid is filled with water.
16+
- Operation #1: addLand(0, 0) turns the water at grid[0][0] into a land. We have 1 island.
17+
- Operation #2: addLand(0, 1) turns the water at grid[0][1] into a land. We still have 1 island.
18+
- Operation #3: addLand(1, 2) turns the water at grid[1][2] into a land. We have 2 islands.
19+
- Operation #4: addLand(2, 1) turns the water at grid[2][1] into a land. We have 3 islands.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<pre><strong>Input:</strong> m = 1, n = 1, positions = [[0,0]]
25+
<strong>Output:</strong> [1]
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>1 &lt;= m, n, positions.length &lt;= 10<sup>4</sup></code></li>
33+
<li><code>1 &lt;= m * n &lt;= 10<sup>4</sup></code></li>
34+
<li><code>positions[i].length == 2</code></li>
35+
<li><code>0 &lt;= r<sub>i</sub> &lt; m</code></li>
36+
<li><code>0 &lt;= c<sub>i</sub> &lt; n</code></li>
37+
</ul>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Follow up:</strong> Could you solve it in time complexity <code>O(k log(mn))</code>, where <code>k == positions.length</code>?</p>
41+
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /