Skip to content

200 number of islands#18

Open
MA-yo-TA wants to merge 2 commits into
mainfrom
200-Number-of-Islands
Open

200 number of islands#18
MA-yo-TA wants to merge 2 commits into
mainfrom
200-Number-of-Islands

Conversation

@MA-yo-TA

Copy link
Copy Markdown
Owner

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))

@kitano-kazuki kitano-kazuki Jun 28, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

個人的には内部関数で使用する変数は、内部関数の定義前に宣言されて欲しいと思いました。

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.

ありがとうございます。確かに(読む順で)未定義の変数が使われていると読みづらいのでそうしようと思います。


class Solution:
def numIslands(self, grid: list[list[str]]) -> int:
def detect_whole_island(row: int, column: 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.

detectというとある島を発見した瞬間みたいな印象を受けるのでexploreの方がいいのではないかと思いました。

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.

なるほど。個人的には explore という過程があってその結果何が分かるのかが表現されている方が好きなんですが、「島全体」というニュアンスはたしかに explore の方がわかりやすいかもしれませんね。

命名の参考にします。

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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

seen_nodesの定義はこの関数の上でもいいのではと思いました。定義されてもない、引数として渡されてもいないものが出てくると若干びっくりするので。

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.

そうですね。関数をインラインで書くにしても変数の宣言・定義の場所は考えた方がよさそうです。ありがとうございますmm

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.

3 participants