200 number of islands#18
Open
MA-yo-TA wants to merge 2 commits into
Open
Conversation
| def numIslands(self, grid: list[list[str]]) -> int: | ||
| def detect_whole_island(row: int, column: int): | ||
| nodes_to_see: deque[tuple[int, int]] = deque([(row, column)]) | ||
| seen_nodes.add((row, column)) |
There was a problem hiding this comment.
個人的には内部関数で使用する変数は、内部関数の定義前に宣言されて欲しいと思いました。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。確かに(読む順で)未定義の変数が使われていると読みづらいのでそうしようと思います。
mt2324
reviewed
Jun 29, 2026
|
|
||
| class Solution: | ||
| def numIslands(self, grid: list[list[str]]) -> int: | ||
| def detect_whole_island(row: int, column: int): |
There was a problem hiding this comment.
detectというとある島を発見した瞬間みたいな印象を受けるのでexploreの方がいいのではないかと思いました。
Owner
Author
There was a problem hiding this comment.
なるほど。個人的には explore という過程があってその結果何が分かるのかが表現されている方が好きなんですが、「島全体」というニュアンスはたしかに explore の方がわかりやすいかもしれませんね。
命名の参考にします。
mt2324
reviewed
Jun 29, 2026
| def numIslands(self, grid: list[list[str]]) -> int: | ||
| def detect_whole_island(row: int, column: int): | ||
| nodes_to_see = deque([(row, column)]) | ||
| seen_nodes.add((row, column)) |
There was a problem hiding this comment.
seen_nodesの定義はこの関数の上でもいいのではと思いました。定義されてもない、引数として渡されてもいないものが出てくると若干びっくりするので。
Owner
Author
There was a problem hiding this comment.
そうですね。関数をインラインで書くにしても変数の宣言・定義の場所は考えた方がよさそうです。ありがとうございますmm
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.
この問題:https://leetcode.com/problems/number-of-islands/
次の問題:https://leetcode.com/problems/max-area-of-island/