695. Max Area of Island - #56
Open
skypenguins wants to merge 1 commit into
Open
Conversation
nodchip
reviewed
Jul 30, 2026
|
|
||
| ### 正答 | ||
| - 以下の正答を読んで `200. Number of Islands` の時のDFSの方法で解いていれば、素直に面積を求められたかもしれないと思った。 | ||
| - Union-Findは実装が複雑になりがち |
There was a problem hiding this comment.
自分は面接本番で Union Find をバグなく書ける自信がありません。仮に面接で Union Find を使いたい場面が出てきたら、「Union Find の実装がすでにあるという仮定のものとで進めて良いですか?」と面接官に尋ねると思います。ただし、経路の圧縮、ランクまたはサイズでどちらを親にするか、時間計算量がアッカーマン関数の逆関数、といったところは軽く触れると思います。
| visited = [[False] * num_cols for _ in range(num_rows)] | ||
|
|
||
| def area_of_island(start_row, start_col): | ||
| to_visit_cells = [(start_row, start_col)] |
There was a problem hiding this comment.
to_visit_cells は英語として語順が不自然に感じました。 cells_to_visit のほうが良いと思います。
| visited = [[False] * num_cols for _ in range(num_rows)] | ||
|
|
||
| def area_of_island(row, col): | ||
| if ( |
There was a problem hiding this comment.
iterative DFS で書かれたように、数直線上に一直線上になるように書いたほうが、読み手にとって読みやすくなると思います。
if not (
0 <= row < num_rows
and 0 <= col < num_cols
and not visited[row][col]
and gird[row][vol] == LAND):
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
695. Max Area of Island
次回予告: 776. Split BST