Skip to content

Arai60/82#6

Open
liruly wants to merge 2 commits intomainfrom
Arai60/82
Open

Arai60/82#6
liruly wants to merge 2 commits intomainfrom
Arai60/82

Conversation

@liruly
Copy link
Copy Markdown
Owner

@liruly liruly commented Jan 11, 2026

82. Remove Duplicates from Sorted List II

Comment on lines +79 to +91
while (node != nullptr) {
if (node->next != nullptr && node->val == node->next->val) {
int dupVal = node->val;
while (node != nullptr && node->val == dupVal) {
node = node->next;
}
unique->next = node;
} else {
node = node->next;
unique = unique->next;
}
}
return dummy.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.

Rinta-Rinta/LeetCode_arai60#3 (comment)
https://discord.com/channels/1084280443945353267/1195700948786491403/1196701558382018590

処理が分岐する際に、処理の長さや簡単さによってはif-elseで並べずにcontinueやbreakで抜ける方が、
分かりやすい場合もありそうです。

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.

なるほど、大事なご指摘だと思います。
特にシンプルな処理の場合は、先にcontinueで抜けた方が可読性が上がる場面も多いと感じました。
ありがとうございます🙏

Comment on lines +23 to +24
- headが重複している場合のエッジケースの考慮が必要
- 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.

この方法でもできるはずですが、確かに大変です。Step 2の方法で、重複していない先頭が見つかるまでは別のループを前につけるか、そうでなければ、保存するノードが見つかったときに、先頭が見つかっているかいなかで条件分岐します。

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.

なるほど、番兵を用意するか条件分岐で実現できますね。ありがとうございます。
愚直にも実装できるようにはしておきたいと思います。

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