Skip to content

Create 234. Palindrome Linked List.md#22

Open
Kitaken0107 wants to merge 2 commits intomainfrom
Kitaken0107-patch-24
Open

Create 234. Palindrome Linked List.md#22
Kitaken0107 wants to merge 2 commits intomainfrom
Kitaken0107-patch-24

Conversation

@Kitaken0107
Copy link
Owner

# self.next = next
class Solution:
def isPalindrome(self, head: Optional[ListNode]) -> bool:
val_list = []
Copy link

Choose a reason for hiding this comment

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

https://discord.com/channels/1084280443945353267/1192728121644945439/1244281685818740737
をご参照ください。

また、型が list であることが分かっているため、変数名に list を入れる必要はないと思います。 values あたりがよいと思います。

Comment on lines +18 to +22
val_list.append(head.val)

while head and head.next:
head = head.next
val_list.append(head.val)
Copy link

Choose a reason for hiding this comment

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

head はリストの最初のノードを表します。 head を動かしている点に違和感を感じました。 node などの変数に一度代入し、 node を動かしていくとよいと思います。

また、リストの辿り方がやや複雑に感じました。

node = head
while node:
    val_list.append(node.val)
    node = node.next

のほうがシンプルだと思います。

Copy link

Choose a reason for hiding this comment

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

ループの先頭で、不必要に主役が変更されています。

また、head and head.next の head は不要では?

while head and head.next:
head = head.next
val_list.append(head.val)
left = 0
Copy link

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.

3 participants