Skip to content

695. Max Area of Islands#18

Open
tNita wants to merge 1 commit into
mainfrom
add/695_max_area_of_island
Open

695. Max Area of Islands#18
tNita wants to merge 1 commit into
mainfrom
add/695_max_area_of_island

Conversation

@tNita
Copy link
Copy Markdown
Owner

@tNita tNita commented Apr 12, 2026

この問題: Max Area of Island
次の問題: Word Ladder

Number of Connected Components in an Undirected Graph は有料問題なので一旦スキップ

def is_inside_island(i: int, j: int):
return 0 <= i < height and 0 <= j < width

def explorer_and_get_size_island(start: tuple[int]) -> int:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

関数名の初めには動詞を使うことが多い気がします
explore_and_get_size_islandの方が文法的にも違和感がないです

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、確かにそうですね。ご指摘ありがとうございます。

Comment on lines +170 to +179
i, j = stack.pop()
if not is_inside_island(i, j) or grid[i][j] == self.WATER or visited[i][j]:
continue
visited[i][j] = True
area_size += 1
stack.append((i - 1, j))
stack.append((i + 1, j))
stack.append((i, j - 1))
stack.append((i, j + 1))
return area_size
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manato110/LeetCode-arai60#17 (comment)
私自身このようなコメントを受けたのですが、
i, jは行列に使うことはあれど、座標に用いられることはあまりないようです。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどです。

(r, c) (row, col) あたりを使うと自然になると思います。

確かにこっちの方がわかりやすいですね。

Comment on lines +181 to +187
max_are_size = 0
for i in range(height):
for j in range(width):
if not visited[i][j] and grid[i][j] == self.LAND:
area_size = explorer_and_get_size_island((i, j))
max_are_size = max(max_are_size, area_size)
return max_are_size
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恐らくmax_area_sizeの誤字でしょうか...?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ、そうです。。。タイポでした。。。

@Manato110
Copy link
Copy Markdown

is_inside_islandなどで関数化してコードを見やすくする工夫がされてとても良いと思いました!
有料問題について、NeetCodeと呼ばれるサイトで同問題ができるようです
https://neetcode.io/problems/count-connected-components/question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants