Skip to content

Commit e53888e

Browse files
committed
827-making-a-large-island.md Removed ISLAND_BASE_ID.
1 parent d767790 commit e53888e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

solutions/1-1000/827-making-a-large-island.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ And this graph may have multiple **connected components** (islands):
4949
![](../../images/graph_undirected_2.png)
5050

5151
## 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).
5656
1. Iterate through each `0` (water), then sum the areas (`land_count`) of neighboring islands.
5757
1. Record the max area and return it.
5858

@@ -63,14 +63,12 @@ And this graph may have multiple **connected components** (islands):
6363
## Python
6464
```python
6565
class Solution:
66-
ISLAND_BASE_ID = 1000000
67-
6866
def __init__(self):
6967
self.result = 0
7068
self.grid = None
71-
self.island_id = self.ISLAND_BASE_ID
7269
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
71+
self.island_id = 2
7472

7573
def largestIsland(self, grid: List[List[int]]) -> int:
7674
self.grid = grid
@@ -145,7 +143,7 @@ class Solution:
145143

146144
used_island_ids.add(island_id)
147145

148-
return self.land_counts[island_id - self.ISLAND_BASE_ID]
146+
return self.land_counts[island_id]
149147
```
150148

151149
## Java

0 commit comments

Comments
 (0)