Skip to content

83. Remove Duplicates from Sorted List#3

Open
rimokem wants to merge 1 commit into
mainfrom
0083-remove-duplicates-from-sorted-list
Open

83. Remove Duplicates from Sorted List#3
rimokem wants to merge 1 commit into
mainfrom
0083-remove-duplicates-from-sorted-list

Conversation

@rimokem
Copy link
Copy Markdown
Owner

@rimokem rimokem commented Mar 22, 2026

Comment thread 0083/memo.md
という流れになっている。

個人的には、多重ループになっていない後者の方が読みやすいと思う。
ただ、リストに重複が多い場合は重複の分`node is not None`の評価が余計に行われるため、パフォースは前者の方が良さそう。
Copy link
Copy Markdown

@h-masder h-masder Mar 22, 2026

Choose a reason for hiding this comment

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

パフォーマンスの議論をするほどの問題ではないと思います。
パフォーマンスの議論の際は、「それぞれの処理時間は〇〇と××程度で、△△のようなケースでは後者が問題になる」といった形で整理されていると、より分かりやすくなると思います。

小田さんの記事も読んでみてください。
https://nuc.hatenadiary.org/entry/2025/11/29/#%E9%80%9F%E5%BA%A6%E3%81%AE%E6%9C%80%E9%81%A9%E5%8C%96

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.

h-masderさん、レビューと記事のご共有ありがとうございます。
とても参考になりました。

メモを書いたときは、すべてのノードが同じ値を持っていた場合、isの判定がn(リストの長さ)回分多く行われるな、とぼんやり思っていました。
ただ、今冷静に考えるとこれはループ内の任意の処理に言えることですね。
ループ内のナノ秒単位の処理を削ることと可読性を天秤にかけるのは、確かに少しズレていました。

今後パフォーマンスについて議論する際は、定量的に整理するように気をつけます。

Comment thread 0083/memo.md
node = head

while node is not None:
while (node.next is not None) and (node.val == node.next.val):
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://google.github.io/styleguide/pyguide.html#33-parentheses

Use parentheses sparingly.

It is fine, though not required, to use parentheses around tuples. Do not use them in return statements or conditional statements unless using parentheses for implied line continuation or to indicate a tuple.

なお、このスタイルガイドは“唯一の正解”というわけではなく、数あるガイドラインの一つに過ぎません。チームによって重視される書き方や慣習も異なります。そのため、ご自身の中に基準を持ちつつも、最終的にはチームの一般的な書き方に合わせることをお勧めします。

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