-
Notifications
You must be signed in to change notification settings - Fork 0
Remove duplicates from sorted list #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: arai60
Are you sure you want to change the base?
Conversation
|
再帰を使った方法でも解いてみると勉強になると思います。 |
| @@ -0,0 +1,33 @@ | |||
| """ | |||
| Reference: | |||
| Ryotaro25: https://github.com/Ryotaro25/leetcode_first60/pull/3/files phase1の新しくListNodeを制作して末端の値と等しくなければ飛ばすコードを真似して書いてみた | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
odaさんのコメントと関連するかもしれませんが、headという変数が動くのは個人的には違和感ありました
問題
https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/?envType=problem-list-v2&envId=xo2bgr0r