Conversation
huyfififi
left a comment
There was a problem hiding this comment.
非常に読みやすかったです。実行時間についての考察やUnion Findなどの様々なやり方にトライされていて良いと思います!
| } | ||
|
|
||
| var seenIslands = <(int, int)>{}; | ||
| var islandCount = 0; |
There was a problem hiding this comment.
isから始まる変数名は boolean型に使われることが多いと思います、英語で読んだとき "Is land count (?)" のように聞こえるので。今回の場合、landCountのみで十分伝わると思います。
There was a problem hiding this comment.
レビューありがとうございます!
確かに is から始まっていますが、キャメルケースにしているためそこまで問題ないのかなと思うのと、今回の問題上 land と island は異なる概念であり、連なった land が一つの island を形成するため、個人的には island のまま行きたいなという気持ちです。
is を避けるのであれば、totalIslands なども良いのかなと思います。
There was a problem hiding this comment.
ご指摘全て納得感あります。確かに問題設定的に「landCount」は不適ですね、ありがとうございます。
語感を変えるなら「numIslands」も良いと思います。 -> 問題で既に関数名として使われているのですね、失礼いたしました。
| } | ||
| } | ||
|
|
||
| return places.getSetCount() - numberWaters; |
There was a problem hiding this comment.
些末ですが…
setは集合の意で使っていると予想しますが、getと並ぶとget/setの文脈と混同します。groupCount など被らない単語がなお良いと思いました。
There was a problem hiding this comment.
レビューありがとうございます。
確かに get, set を並べるのはわかりづらいですね。気をつけます。
| } | ||
|
|
||
| var seenPlaces = <(int, int)>{}; | ||
| var placesToCheck = <(int, int)>[]; |
There was a problem hiding this comment.
サブルーチン traverseIsland の中だけで使うので、ここでは不要です?
| var placesToCheck = <(int, int)>[]; |
| return 0; | ||
| } | ||
|
|
||
| var seenPlaces = <(int, int)>{}; |
There was a problem hiding this comment.
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 かな。 |
解いた問題:https://leetcode.com/problems/number-of-islands/description/
次に解く問題:https://leetcode.com/problems/max-area-of-island/description/