Skip to content

Conversation

@SuperHotDogCat
Copy link
Owner

@TORUS0818
Copy link

再帰を使った方法でも解いてみると勉強になると思います。
(私の場合はなりました。)

@@ -0,0 +1,33 @@
"""
Reference:
Ryotaro25: https://github.com/Ryotaro25/leetcode_first60/pull/3/files phase1の新しくListNodeを制作して末端の値と等しくなければ飛ばすコードを真似して書いてみた

Choose a reason for hiding this comment

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

空間計算量についての違いもメモとして追記すると良いかなと思いました。

while head.next and head.val == head.next.val:
head.next = head.next.next
head = head.next
return dummy_head No newline at end of file
Copy link

Choose a reason for hiding this comment

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

ファイルの末尾は改行で終えましょう。

@@ -0,0 +1,9 @@
class Solution:
def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
dummy_head = head
Copy link

Choose a reason for hiding this comment

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

dummy といっているのは大抵の場合実際は不要なのだがループの回し方の都合上形式的に必要なものの場合で実際にそれを返すならば、こちらを head にしてループを node あたりで回したらどうでしょう。

while head.next and head.val == head.next.val:
# recconect listnodes in order to delete duplicates
head.next = head.next.next
head = head.next
Copy link

Choose a reason for hiding this comment

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

odaさんのコメントと関連するかもしれませんが、headという変数が動くのは個人的には違和感ありました

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.

6 participants