Skip to content

200. Number of Islands#46

Open
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-200
Open

200. Number of Islands#46
skypenguins wants to merge 1 commit into
mainfrom
leetcode/arai60/problem-200

Conversation

@skypenguins

Copy link
Copy Markdown
Owner

200. Number of Islands

次回予告: 209. Minimum Size Subarray Sum

@skypenguins skypenguins self-assigned this Jul 12, 2026
Comment thread memo.md
if grid is None:
return 0

rows, cols = len(grid), len(grid[0])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
subaru-hello/leetcode-arai60#19 (comment)

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.

確かにこの場合は num_ をつけた方がより中身を表していると思いました。

Comment thread memo.md
if grid is None:
return 0

rows, cols = len(grid), len(grid[0])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

複数への変数への代入を 1 行で行っても、読み手にとってはあまり読みやすくならないと思います。 1 行で 1 つずつ変数を定義することをお勧めいたします。
変数の値を swap する場合は例外だと思います。

Comment thread memo.md
if r < 0 or r >= rows or c < 0 or c >= cols or grid[r][c] != '1':
return

grid[r][c] = '0' # 訪問済みマークとして自分自身を'0'に書き換える

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
Hiroto-Iizuka/coding_practice#17 (comment)

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.

入力値を直接書き換えている方法は確かに今回の場合も含めてほとんどの場合ではあまり良くないですね。ご指摘ありがとうございます。

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants