82. Remove Duplicates from Sorted List II#5
Open
tNita wants to merge 1 commit into
Open
Conversation
ee45856 to
e8a7cd9
Compare
oda
reviewed
Dec 21, 2025
| - rightが重複要素であることの判定 | ||
| - 直前の要素の値 == 今の要素の値 or (直後の要素がNoneか今の要素の値 == 直後の要素の値) | ||
| - 解いている中で境界条件が甘く、先頭をきちんと考慮できていないことに気づく | ||
| (アクセプトされなかったコード) |
|
|
||
| - https://hackage.haskell.org/package/base-4.19.0.0/docs/Data-List.html#v:group | ||
| - Pythonのgroup→filter→concatの順に見えるので、なんでconcat. filter. groupなのかが疑問だった | ||
| - おそらくHaskellの書き方をもとにしてそうとわかり納得 |
nodchip
reviewed
Dec 22, 2025
| left.next = None | ||
| return head | ||
|
|
||
| def isDuplicate(self, prev_node_val: int, node: ListNode) -> bool: |
There was a problem hiding this comment.
is(動詞の原形) は、英語句としてやや不自然に感じました。 isDuplicated はいかがでしょうか?
mamo3gr
reviewed
Dec 22, 2025
Comment on lines
+15
to
+18
| - 重複を全部削除する→重複している要素の直前の要素を基準とする必要がありそう | ||
| - 重複している直前の要素を特定してから、重複している要素の直後の要素を特定できればそれらを繋げることで目的を達成できそう | ||
| - その重複している要素の直前の要素、直後の要素はどう特定するのか? | ||
| - 二つのポインタ直前の要素left、直後の要素rightを持ってそれを動かしていけば良さそう→rightを主役にループを回す |
mamo3gr
reviewed
Dec 22, 2025
Comment on lines
+277
to
+278
| tail = dummy | ||
| node = head |
There was a problem hiding this comment.
tail は処理済みのノードを繋げていく先だということが、名前に情報をもう少し付け足せると親切に思いました(中盤で初めてそうだと分かる。それまでは node とセットで探索につかうポインタなのかな?とも思いました)
Owner
Author
There was a problem hiding this comment.
確かにそう見えますね。ご指摘ありがとうございます。
以下のようにすると探索には使わないよということがはっきりしますかね。
result_dummy = ListNode()
result_tail = result_dummy
node = head
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
この問題:https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/description/
次に解く問題:https://leetcode.com/problems/add-two-numbers/description/