Open
Conversation
oda
reviewed
May 24, 2024
| for i, node in enumerate(lists): | ||
| if not node: | ||
| continue | ||
| heapq.heappush(min_heap, (node.val, i, node)) |
There was a problem hiding this comment.
これがないと、定義されていないListNodeの比較になって問題が出るのですかね。
Owner
Author
There was a problem hiding this comment.
問題文上は不要です。
これがないと、定義されていないListNodeの比較になって問題が出るのですかね。
おっしゃる通りで、同値の比較のために入れていました。
この旨はコメントで書いておかないと、疑問を持たれてしまいますね。
There was a problem hiding this comment.
同じ値があったときに、オブジェクトの < が定義されていないからエラーということですね。
liquo-rice
reviewed
May 24, 2024
| for i, node in enumerate(lists): | ||
| if not node: | ||
| continue | ||
| heapq.heappush(min_heap, (node.val, i, node)) |
There was a problem hiding this comment.
これがないと、定義されていないListNodeの比較になって問題が出るのですかね。
| node = sentinel | ||
| while min_heap: | ||
| val, index, smallest_head = heapq.heappop(min_heap) | ||
| node.next = ListNode(val) |
Owner
Author
There was a problem hiding this comment.
こういうことですかね。
val, index, smallest_head = heapq.heappop(min_heap)
node.next = smallest_head
node = node.next既存のノードのnextは必ず上書きされるので、新しく作った方が分かりやすいかなと考えてました。
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/merge-k-sorted-lists/