Skip to content

141. Linked List Cycle#2

Open
tNita wants to merge 3 commits into
mainfrom
add/141_linked_list_cycle
Open

141. Linked List Cycle#2
tNita wants to merge 3 commits into
mainfrom
add/141_linked_list_cycle

Conversation

@tNita
Copy link
Copy Markdown
Owner

@tNita tNita commented Nov 16, 2025

@tNita tNita force-pushed the add/141_linked_list_cycle branch from 5c903ae to c7cad2f Compare November 16, 2025 03:02
@TakayaShirai
Copy link
Copy Markdown

TakayaShirai commented Nov 16, 2025

初回にも関わらず 複数の人のコードやコメントを参照しているのが素晴らしいなと感じました!
初回ではありませんでしたが、それでも素晴らしいと思います!

Comment on lines +52 to +55
for m in visited_node:
if m is node:
return True
visited_node.append(node)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

おそらく、memo の m を表現していると思うのですが、読み手が変数が何を表しているかを想像する必要があり、認知負荷が高そうです。また、要素が複数あるリストを visited_node と単数で表現するのは個人的に違和感があります(visited なら単数、複数どちらでもとれそう)。もし書くとしたら以下のような感じはどうでしょう。

Suggested change
for m in visited_node:
if m is node:
return True
visited_node.append(node)
for visited_node in visited_nodes:
if node is visited_node:
return True
visited_nodes.append(node)

Copy link
Copy Markdown
Owner Author

@tNita tNita Nov 16, 2025

Choose a reason for hiding this comment

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

@TakayaShirai

コメントありがとうございます!

memo の m を表現していると思う

はい、そうです。。。

完全に思考時の「メモ」に引っ張られていました。。。

また、要素が複数あるリストを visited_node と単数で表現するのは個人的に違和感があります(visited なら単数、>複数どちらでもとれそう)。もし書くとしたら以下のような感じはどうでしょう。

for visited_node in visited_nodes:
    if node is visited_node:
        return True
visited_nodes.append(node)

確かに良さそうですね!参考にさせていただきます。

Comment on lines +11 to +13
for visited_node in visited_nodes:
if node is visited_node:
return True
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

while文の中でvisited_nodesにnodeが含まれているかの確認のためにfor文を利用していますが、ここはinを利用してfor文を無くすとネストも一段浅くなり読みやすくなるので良いと思いました。

Suggested change
for visited_node in visited_nodes:
if node is visited_node:
return True
if node in visited_nodes:
return True

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.

あ、確かにin使えましたね!ありがとうございます。

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.

3 participants