Skip to content

82. Remove Duplicates from Sorted List II#6

Open
xbam326 wants to merge 3 commits into
mainfrom
82
Open

82. Remove Duplicates from Sorted List II#6
xbam326 wants to merge 3 commits into
mainfrom
82

Conversation

@xbam326
Copy link
Copy Markdown
Owner

@xbam326 xbam326 commented Dec 28, 2025

今回解いた問題

Remove Duplicates from Sorted List II

次回解く予定の問題

Add Two Numbers

```
class Solution:
def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
targetNode = head
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
tNita/arai60#3 (comment)

Copy link
Copy Markdown
Owner Author

@xbam326 xbam326 Dec 30, 2025

Choose a reason for hiding this comment

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

こちら元々の関数名がcamelCaseだったので踏襲していたのですが、元々Pythonではsnake_caseが一般的と私も認識しており、実際のコーディング面接の機会になった際に慣れでcamelCaseで書いてしまうと不要な問答が生じてしまいそうなので今後snake_caseで書くようにいたします。

https://github.com/mamo3gr/arai60/pull/4/files
こちらの方のコードを読んだ
skip_toとかlast_fixedのような変数名はわかりやすかった
連結リストあんまり慣れてない自分にとっては気にするnodeがlast_fixedと.nextと.next.nextの3つあってlast_fixed.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.

https://1kohei1.com/leetcode/ からリンクされている解説動画が分かりやすかったです。
気にするのは last_fixed.nextlast_fixed.next.next で、重複がないことを確認できたら last_fixed をひとつ先に進めます。

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.

ありがとうございます。
リンクに動画がついていたの全く気づいていませんでした。
見たところだいぶイメージがつかめました。

if distinctNumNodeTail:
distinctNumNodeTail.next = None
```
付け替えた後に、元々付け替えたNodeには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.

これ要するに不変条件はなにかということです。
引き継ぎの時に何を約束しているのかという話を延々しています。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.xzxd7jwvkwc5

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.

4 participants