Wanwan87 2. add two numbers 1#5
Open
wanwan87 wants to merge 4 commits into
Open
Conversation
hiro111208
reviewed
May 11, 2026
Comment on lines
+138
to
+145
| if l1 is not None: | ||
| value1 = l1.val | ||
| else: | ||
| value1 = 0 | ||
| if l2 is not None: | ||
| value2 = l2.val | ||
| else: | ||
| value2 = 0 |
There was a problem hiding this comment.
個人的にはこっちの方が2行で済んで読みやすいかと思いました。
value1 = l1.val if l1 is not None else 0
value2 = l2.val if l2 is not None else 0
Comment on lines
+151
to
+154
| if l1 is not None: | ||
| l1 = l1.next | ||
| if l2 is not None: | ||
| l2 = l2.next |
There was a problem hiding this comment.
ここに関しても同様です。
l1 = l1.next if l1 else None
l2 = l2.next if l2 else None| value2 = l2.val | ||
| else: | ||
| value2 = 0 | ||
| tmp = value1 + value2 + carry |
There was a problem hiding this comment.
ここの変数名は例えばdigit_sumとするとtmpよりもわかりやすいと思います。
Owner
Author
There was a problem hiding this comment.
ありがとうございます、tmpは何が入っているか分かりにくいですね
nodchip
reviewed
May 12, 2026
| add_result = ListNode() | ||
| carry = 0 | ||
| while l1 is not None and l2 is not None: | ||
| tmp = l1.val+l2.val |
There was a problem hiding this comment.
+ の両側にスペースが空けるのと空いていないのが統一されていない点が気になりました。空けるほうに統一するとよいと思います。
Owner
Author
There was a problem hiding this comment.
ありがとうございます、自分もあけてある方が読みやすいのでそちらで統一します
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/
次の問題:https://leetcode.com/problems/valid-parentheses/description/