Graph bfs dfs 695#18
Open
hiroki-horiguchi-dev wants to merge 4 commits into
Open
Conversation
quinn-sasha
reviewed
May 24, 2026
| } | ||
|
|
||
| // find land | ||
| if (element == 1 && !visited[rowIndex][columnIndex]) { |
There was a problem hiding this comment.
Step1 みたいに、探索の処理は関数に切り出した方が読みやすいと思いました
hroc135
reviewed
May 24, 2026
| return maxAreaOfIslands; | ||
| } | ||
|
|
||
| private int countNumberOfIslands(int[][] grid, boolean[][] visited, int rowIndex, int columnIndex) { |
There was a problem hiding this comment.
この関数名だと grid 内の島の数を数えているように見えました。 countAreaOfIsland などいかがでしょう?
hroc135
reviewed
May 24, 2026
| int element = grid[rowIndex][columnIndex]; | ||
|
|
||
| // if element is not land or water. | ||
| if (element != 1 && element != 0) { |
There was a problem hiding this comment.
0, 1は water, land のような定数にした方が扱いやすいと思いました。
There was a problem hiding this comment.
そうすれば if (element == land) のように書くことができ、可読性があがるので // if element is land. のようなコメントを削れると思います
hroc135
reviewed
May 24, 2026
|
|
||
| for (int rowIndex = 0; rowIndex < grid.length; rowIndex++) { | ||
| for (int columnIndex = 0; columnIndex < grid[0].length; columnIndex++) { | ||
| int element = grid[rowIndex][columnIndex]; |
There was a problem hiding this comment.
element という変数名には情報が乏しいと思いました(あらゆる配列の要素に関して使えてしまう)。grid の中のセルという意味で cell はどうでしょう?
This reverts commit 947fb51.
jjysogfy
reviewed
May 24, 2026
Comment on lines
+121
to
+128
| // count top | ||
| if (previousRowIndex >= 0 | ||
| && grid[previousRowIndex][currentColumnIndex] == 1 | ||
| && !visited[previousRowIndex][currentColumnIndex] | ||
| ) { | ||
| visited[previousRowIndex][currentColumnIndex] = true; | ||
| lands.add(new int[]{previousRowIndex,currentColumnIndex}); | ||
| } |
There was a problem hiding this comment.
この処理は4回くり返し書くにはちょっと長く感じました。メソッドに切り出す、長さ4の配列を作りループする、など対処法がコメント集にあったと思うので、見ていなければ見てみると参考になるかもしれません。
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を解きました、レビューお願いします