Skip to content

Add Two Numbers#1

Merged
Exzrgs merged 3 commits intomainfrom
arai60-add-two-numbers
Apr 26, 2024
Merged

Add Two Numbers#1
Exzrgs merged 3 commits intomainfrom
arai60-add-two-numbers

Conversation

@Exzrgs
Copy link
Copy Markdown
Owner

@Exzrgs Exzrgs commented Apr 26, 2024

Comment on lines +25 to +26
l1 = l1.next
l2 = l2.next
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.

ここ抜くの忘れてました。
無視してください🙏

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

削除、コミット、 git push で修正できると思います。レビューワーの負担を下げるため、修正してからレビュー依頼を頂けるとありがたかったです。

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.

承知しました!
以後そうします🙏


class Solution:
def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
head = ListNode(-1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

head は、現在注目しているノード、リストの先端のノードを表すことが多いと思います。 dummy または sentinel はいかがでしょうか?

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.

ご指摘ありがとうございます。
dummyを使おうと思います!

Comment on lines +25 to +26
l1 = l1.next
l2 = l2.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.

削除、コミット、 git push で修正できると思います。レビューワーの負担を下げるため、修正してからレビュー依頼を頂けるとありがたかったです。


c = 0
while l1 and l2:
s = (l1.val + l2.val + c)%10
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% の両隣にスペースを空けたほうが良いと思います。

PEP8 では、演算子の優先順位の異なる複数の演算子を1 つの式で用いる場合、順位の低い演算子の両隣にスペースを空けることを推奨しています。
https://peps.python.org/pep-0008/#other-recommendations

Google Python Style Guide では、適切に判断してください、としています。
https://google.github.io/styleguide/pyguide.html#36-whitespace

PEP8 と Google Python Style Guide を一通り読まれることをお勧めします。

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.

ありがとうございます。
読みます🙏

carry = 0
while l1 or l2 or carry:
sum_val = carry
if l1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sum_val += l1.val if l1 else 0 という書き方もあります。 l1 = l1.next if l1 else None と組み合わせると if 文が消せます。ただ、これで読みやすくなっているかと言われると、微妙なところです。

if l2:
sum_val += l2.val
l2 = l2.next
carry = sum_val//10
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// の両隣にスペースを空けるとよいと思います。

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.

本当ですね....
修正します🙏

Copy link
Copy Markdown

@nodchip nodchip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よいと思います。

@Exzrgs Exzrgs merged commit 77e8855 into main Apr 26, 2024
@rihib rihib mentioned this pull request Aug 6, 2024
@Exzrgs Exzrgs mentioned this pull request Oct 19, 2024
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.

2 participants