200. Number of Islands#46
Open
skypenguins wants to merge 1 commit into
Open
Conversation
nodchip
reviewed
Jul 13, 2026
| if grid is None: | ||
| return 0 | ||
|
|
||
| rows, cols = len(grid), len(grid[0]) |
There was a problem hiding this comment.
こちらのコメントをご参照ください。
subaru-hello/leetcode-arai60#19 (comment)
Owner
Author
There was a problem hiding this comment.
確かにこの場合は num_ をつけた方がより中身を表していると思いました。
| if grid is None: | ||
| return 0 | ||
|
|
||
| rows, cols = len(grid), len(grid[0]) |
There was a problem hiding this comment.
複数への変数への代入を 1 行で行っても、読み手にとってはあまり読みやすくならないと思います。 1 行で 1 つずつ変数を定義することをお勧めいたします。
変数の値を swap する場合は例外だと思います。
| if r < 0 or r >= rows or c < 0 or c >= cols or grid[r][c] != '1': | ||
| return | ||
|
|
||
| grid[r][c] = '0' # 訪問済みマークとして自分自身を'0'に書き換える |
There was a problem hiding this comment.
こちらのコメントをご参照ください。
Hiroto-Iizuka/coding_practice#17 (comment)
Owner
Author
There was a problem hiding this comment.
入力値を直接書き換えている方法は確かに今回の場合も含めてほとんどの場合ではあまり良くないですね。ご指摘ありがとうございます。
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.
200. Number of Islands
次回予告: 209. Minimum Size Subarray Sum