Conversation
nodchip
reviewed
Mar 16, 2024
| def listNodeToNumber(self, l: ListNode) -> int: | ||
| node = l | ||
| power = 1 | ||
| number = 0 |
There was a problem hiding this comment.
Python で int に代入することのできる値の範囲はいくつからいくつまでですか?また、ほかの主要な言語ではどうですか?
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます!
Pythonではintにメモリが許す分大きな値をいれることができます. そのため, intに代入することのできる値の範囲はメモリの大きさや処理系(CPythonかどうか, 64bit platformか)に依存します. 今回はlinked listの長さがたかだか100だったから良かったものの, 長さが大きくなるとそういったところも考えなければいけなくなるのですね.
また, 他の主要な言語では可変長整数は一般的ではなく, 扱える値の範囲は決まっております.
このold.pyの解答はpythonだからこそ簡単そうに実装できたということで, もし高速化のためc++で実装しようとなったときにはこの方針は使えませんね.
大変勉強になりました.
| carry = 0 | ||
| while True: | ||
| digit_sum = None | ||
| if l1 is None and l2 is None: |
There was a problem hiding this comment.
while 文をシンプルにするため、 l1 is None and l2 is None を while 文の条件式にし、 carry の処理を while 文の外で行ったほうがよいと思いました。
Owner
Author
There was a problem hiding this comment.
なるほど, たしかにおっしゃるとおりですね…
とりあえずwhileをwhile Trueで始めてしまうクセがあるので気をつけます.
ありがとうございます.
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.
Problem link