-
Notifications
You must be signed in to change notification settings - Fork 0
83. Remove Duplicates from Sorted List #2
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: main
Are you sure you want to change the base?
Conversation
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ループの中で重複を見つけたら重複がなくなるまでSkipするみたいな実装(2重ループ)も選択肢としてはあるかもしれないですね。
if head is None: | ||
return None | ||
current = head | ||
while current.next is not None: |
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.
正常系では、1回のループでノードが1つ進むとするとif文はcontinueして、elseを消すのもありかもしれないです。
while current.next is not None:
if current.val == current.next.val:
current.next = current.next.next
continue
current = current.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.
ありがとうございます。
「1回のループでノードが1つ進む感じが伝わる」のと「early returnみたいでスッキリする」ので、いいですね!
https://www.python.jp/news/wnpython311/inline-function.html | ||
|
||
|
||
- Discordを見ていて`current`という変数の命名について無意識についけていたことに気づいた。別の候補として`current_node`や`current_focusing_node`を思いついた。しかし、今回は短い処理であり、今注目しているノードという点は伝わる範囲だと思うので、`current`という変数名を使うことにする。もっと長い処理場合は、より意味のこもった変数名にする。 |
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.
本当に上から読んでいって明らかならば node だけでもいいと思うんですよね。読み手に何を伝えたいか次第です。
for i in range(len(array)):
と書かれていたら、添字の配列であろうとほぼ確信して次にいけるわけです。
これが長くても迷彩か擬態にしかなりません。
https://discord.com/channels/1084280443945353267/1200089668901937312/1209882689411223644
https://discord.com/channels/1084280443945353267/1225849404037009609/1234218057199784077
良いと思います! |
https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/