Open
Conversation
xbam326
reviewed
Jan 11, 2026
Comment on lines
+30
to
+34
| if sum == 0: | ||
| node = ListNode(0) | ||
| return node | ||
|
|
||
| dummy = ListNode() |
There was a problem hiding this comment.
表記の一貫性がない部分が気になりました。
ListNodeのvalの初期値は0となっているので、ListNode()で良いかなと思いました。
There was a problem hiding this comment.
個人的にはこの初期値は使わないのでなんでもいいという意味合いだと思うので、上とはものが違うというのでいいかと思います。
|
|
||
| total = node1_val + node2_val + carry | ||
|
|
||
| digit = total % 10 |
There was a problem hiding this comment.
今回は10で割ったあまりで、今回の解法でいくと次のfixed_tailのvalだと思うので、それが伝わる命名のfixed_tail_valなどだとより意味が伝わり読み手に親切かなと思いました。
Owner
Author
There was a problem hiding this comment.
確かにvalをつけた方が意味が分かりやすいですね。勉強になります。
oda
reviewed
Jan 11, 2026
Comment on lines
+30
to
+34
| if sum == 0: | ||
| node = ListNode(0) | ||
| return node | ||
|
|
||
| dummy = ListNode() |
There was a problem hiding this comment.
個人的にはこの初期値は使わないのでなんでもいいという意味合いだと思うので、上とはものが違うというのでいいかと思います。
Comment on lines
+30
to
+32
| if sum == 0: | ||
| node = ListNode(0) | ||
| return node |
| # self.val = val | ||
| # self.next = next | ||
| class Solution: | ||
| def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: |
There was a problem hiding this comment.
どうやら両方が None である可能性はこの問題では気にしなくて良いようですが、来たら None が返りますね。
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/add-two-numbers/