Conversation
| return current_node | ||
| ``` | ||
| - not ではなく is Noneと書くべきではないのだろうか? | ||
| - not l1, not l2はis None だがnot carry はis 0である。そこを示した方がわかりやすい気がする |
There was a problem hiding this comment.
ここらへんは、派閥ありますね。周りに聞いて合わせましょう。
Google Style Guide は is not None 派。
https://google.github.io/styleguide/pyguide.html#2144-decision
Pep8 はどちらでもいいのかしら。
https://peps.python.org/pep-0008/#programming-recommendations:~:text=Also%2C%20beware%20of%20writing%20if%20x%20when%20you%20really%20mean%20if%20x%20is%20not%20None
| ```python | ||
| class Solution: | ||
| def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: | ||
| dummyHead = ListNode(0) |
There was a problem hiding this comment.
変数名は lower_snake で書くことをおすすめいたします。
https://peps.python.org/pep-0008/#function-and-variable-names
Variable names follow the same convention as function names.
https://google.github.io/styleguide/pyguide.html#316-naming
local_var_name
LeetCode で指定されているものについては、例外として扱ってよいと思います。
|
|
||
| while node1 is not None or node2 is not None or carry != 0: | ||
|
|
||
| node1_val = node1.val if node1 is not None else 0 |
There was a problem hiding this comment.
この周辺、インデントでタブとスペースが混ざっているように思います。スペースでインデントすることをおすすめいたします。
https://peps.python.org/pep-0008/#indentation
Use 4 spaces per indentation level.
https://google.github.io/styleguide/pyguide.html#34-indentation
Indent your code blocks with 4 spaces.
There was a problem hiding this comment.
ありがとうございます。なんとなく使っていたのですがTabはエディタなどが違うと異なって表示されるためspaceが推奨されているのですね。これから注意したいと思います。
| elif node2 is None: | ||
| val = node1.val + carry | ||
|
|
||
| carry = val//10 |
There was a problem hiding this comment.
二項演算子の両隣にスペースを空けるか空けないか、ソースコード間で統一することをおすすめいたします。
問題文
https://leetcode.com/problems/add-two-numbers/description/