Skip to content

Solve 206. Reverse Linked List (step 1, 2)#11

Open
cheeseNA wants to merge 2 commits intomainfrom
206
Open

Solve 206. Reverse Linked List (step 1, 2)#11
cheeseNA wants to merge 2 commits intomainfrom
206

Conversation

@cheeseNA
Copy link
Copy Markdown
Owner

def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
if not head:
return None
node_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.

単に nodes としても良いかもしれません。

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.

そうですね!ありがとうございます.
あとから見て_listは右辺の代入があるから要らないなと気付きました.

cursor = head
prev_node = None
while cursor:
tmp = cursor.next
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tmp は何も表さないため、個人的には避けています。ですが、この規模のコードであれば問題ないかもしれません。

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.

next_nodeという名前も考えていたのですが, どなたかのコメントで"prevもnextも出てくると混乱するのでは"とあったためこの命名にしました. おっしゃるとおり, 大きい規模のコードでは避けるようにします.

Copy link
Copy Markdown

@nodchip nodchip left a comment

Choose a reason for hiding this comment

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

よいと思います。

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.

2 participants