Skip to content

Commit b03d676

Browse files
refactor 305
1 parent 7140bda commit b03d676

File tree

1 file changed

+0
-43
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-43
lines changed

src/main/java/com/fishercoder/solutions/_305.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/**
7-
* 305. Number of Islands II
8-
*
9-
* A 2d grid map of m rows and n columns is initially filled with water.
10-
* We may perform an addLand operation which turns the water at position (row, col) into a land.
11-
* Given a list of positions to operate, count the number of islands after each addLand operation.
12-
* An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically.
13-
* You may assume all four edges of the grid are all surrounded by water.
14-
15-
Example:
16-
17-
Given m = 3, n = 3, positions = [[0,0], [0,1], [1,2], [2,1]].
18-
Initially, the 2d grid grid is filled with water. (Assume 0 represents water and 1 represents land).
19-
20-
0 0 0
21-
0 0 0
22-
0 0 0
23-
Operation #1: addLand(0, 0) turns the water at grid[0][0] into a land.
24-
25-
1 0 0
26-
0 0 0 Number of islands = 1
27-
0 0 0
28-
Operation #2: addLand(0, 1) turns the water at grid[0][1] into a land.
29-
30-
1 1 0
31-
0 0 0 Number of islands = 1
32-
0 0 0
33-
Operation #3: addLand(1, 2) turns the water at grid[1][2] into a land.
34-
35-
1 1 0
36-
0 0 1 Number of islands = 2
37-
0 0 0
38-
Operation #4: addLand(2, 1) turns the water at grid[2][1] into a land.
39-
40-
1 1 0
41-
0 0 1 Number of islands = 3
42-
0 1 0
43-
We return the result as an array: [1, 1, 2, 3]
44-
45-
Challenge:
46-
47-
Can you do it in time complexity O(k log mn), where k is the length of the positions?
48-
*/
496
public class _305 {
507
public static class Solution1 {
518

0 commit comments

Comments
 (0)