You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solutions/1-1000/827-making-a-large-island.md
+7-9
Original file line number
Diff line number
Diff line change
@@ -49,10 +49,10 @@ And this graph may have multiple **connected components** (islands):
49
49

50
50
51
51
## Approach
52
-
1. Change one node from `0` to `1` to make the largest island means combining the adjacent islands of a `0`nodes.
53
-
1. We can mark an island's lands with one same id (`island_id`), and mark another island's lands with another same id. To mark a land, just change its value to the `island_id`.
54
-
1. Use a `map` (or `array`) to map each `island_id` to its area (`land_count`).
55
-
1. How to calculate the area of an island? See [695. Max Area of Island](695-max-area-of-island.md).
52
+
1. Change one node from `0` to `1` to make the largest island means combining the adjacent islands of a `0`node.
53
+
1. We can mark an island's lands with one same id (`island_id`), and mark another island's lands with another `island_id`. To mark a land, just change its value to the `island_id`.
54
+
1. Use a `map` (or an `array`) to map each `island_id` to its area (`land_count`).
55
+
1. How to calculate the area of an island? Using `Depth-First Search` or `Breadth-First Search`. See [695. Max Area of Island](695-max-area-of-island.md).
56
56
1. Iterate through each `0` (water), then sum the areas (`land_count`) of neighboring islands.
57
57
1. Record the max area and return it.
58
58
@@ -63,14 +63,12 @@ And this graph may have multiple **connected components** (islands):
63
63
## Python
64
64
```python
65
65
classSolution:
66
-
ISLAND_BASE_ID=1000000
67
-
68
66
def__init__(self):
69
67
self.result =0
70
68
self.grid =None
71
-
self.island_id =self.ISLAND_BASE_ID
72
69
self.land_count =0
73
-
self.land_counts = []
70
+
self.land_counts = [0, 0] # Since `island_id` starts from 2, the first two records will not be used
0 commit comments