Skip to content

200. Number of Islands#17

Open
TakayaShirai wants to merge 1 commit intomainfrom
200_number_of_islands
Open

200. Number of Islands#17
TakayaShirai wants to merge 1 commit intomainfrom
200_number_of_islands

Conversation

@TakayaShirai
Copy link
Copy Markdown
Owner

@TakayaShirai TakayaShirai self-assigned this Jan 15, 2026
Copy link
Copy Markdown

@huyfififi huyfififi left a comment

Choose a reason for hiding this comment

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

非常に読みやすかったです。実行時間についての考察やUnion Findなどの様々なやり方にトライされていて良いと思います!

}

var seenIslands = <(int, int)>{};
var islandCount = 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.

isから始まる変数名は boolean型に使われることが多いと思います、英語で読んだとき "Is land count (?)" のように聞こえるので。今回の場合、landCountのみで十分伝わると思います。

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.

レビューありがとうございます!

確かに is から始まっていますが、キャメルケースにしているためそこまで問題ないのかなと思うのと、今回の問題上 land と island は異なる概念であり、連なった land が一つの island を形成するため、個人的には island のまま行きたいなという気持ちです。

is を避けるのであれば、totalIslands なども良いのかなと思います。

Copy link
Copy Markdown

@huyfififi huyfififi Jan 15, 2026

Choose a reason for hiding this comment

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

ご指摘全て納得感あります。確かに問題設定的に「landCount」は不適ですね、ありがとうございます。
語感を変えるなら「numIslands」も良いと思います。 -> 問題で既に関数名として使われているのですね、失礼いたしました。

}
}

return places.getSetCount() - numberWaters;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

些末ですが…

setは集合の意で使っていると予想しますが、getと並ぶとget/setの文脈と混同します。groupCount など被らない単語がなお良いと思いました。

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.

レビューありがとうございます。

確かに get, set を並べるのはわかりづらいですね。気をつけます。

}

var seenPlaces = <(int, int)>{};
var placesToCheck = <(int, 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.

サブルーチン traverseIsland の中だけで使うので、ここでは不要です?

Suggested change
var placesToCheck = <(int, int)>[];

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.

不要ですね。ありがとうございます!

return 0;
}

var seenPlaces = <(int, 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.

Landしか記録しないので、seenLands でも良いと思いました。
あと、他の語彙として visited, cell なども選択肢にあると良さそうです。

// https://ja.wikipedia.org/wiki/%E7%B4%A0%E9%9B%86%E5%90%88%E3%83%87%E3%83%BC%E3%82%BF%E6%A7%8B%E9%80%A0
// 二次元配列である grid を、扱いやすい形の素集合データ構造に変えていく過程で Union Find を使用する。
// 小学生の頃に時々やっていた「じゃんけん列車」にかなり近い印象を受けた。
// じゃんけんをして先頭を決める部分が Union に当たり、自分の列車の先頭が Find で見つかる親に当たる。現実だと、親と子の関係は双方向の linked list かな。
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人とは限らないので、双方向にするには少し工夫がいりますね。

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.

4 participants