141. Linked List Cycle#2
Open
tNita wants to merge 3 commits into
Open
Conversation
5c903ae to
c7cad2f
Compare
|
|
Comment on lines
+52
to
+55
| for m in visited_node: | ||
| if m is node: | ||
| return True | ||
| visited_node.append(node) |
There was a problem hiding this comment.
おそらく、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) |
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます!
memo の m を表現していると思う
はい、そうです。。。
完全に思考時の「メモ」に引っ張られていました。。。
また、要素が複数あるリストを visited_node と単数で表現するのは個人的に違和感があります(visited なら単数、>複数どちらでもとれそう)。もし書くとしたら以下のような感じはどうでしょう。
for visited_node in visited_nodes: if node is visited_node: return True visited_nodes.append(node)
確かに良さそうですね!参考にさせていただきます。
t9a-dev
reviewed
Nov 17, 2025
Comment on lines
+11
to
+13
| for visited_node in visited_nodes: | ||
| if node is visited_node: | ||
| return True |
There was a problem hiding this comment.
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 |
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.
This : 141. Linked List Cycle
Next : 142. Linked List Cycle II