Merged
Conversation
fhiyo
reviewed
Jun 1, 2024
| ListNode node = new ListNode(sum % 10); | ||
| ListNode nextL1 = l1 != null ? l1.next : null; | ||
| ListNode nextL2 = l2 != null ? l2.next : null; | ||
| node.next = addTwoNumbers(nextL1, nextL2, carry); |
There was a problem hiding this comment.
多分ケアレスミスでしょうが、 addTwoNumbersHelper() ですかね。
oda
reviewed
Jun 1, 2024
| スタックフレームサイズは、int が 4byte、ListNode が 8byte (64 ビット JVM のとき)であると見積もると、int 変数が3つ、ListNode が3つなので、4*3+8\*3=36byte くらい? | ||
| JVM のデフォルトのスタックサイズは 1MB なので、1M/36byte=27K 回くらい再帰ができるということになる。 | ||
|
|
||
| ほかに気になったものとして以下のところで番兵(sentinel)をつかっているところがあった。しかし、番兵は条件判定処理の回数を減らすために使われるものなので、今回のケースではあまり意味がないように思えたが、あまり確証はもてませんでした。 |
There was a problem hiding this comment.
あ、番兵という言葉はもう少し広いので、ここでいう dummy を指したりもします。
たぶん、「境界条件の判定の簡略化のために使う値」くらいの意味だと思っているようですが、「境界に置く、本来の意味を持たないデータ」くらいの意味で使うので、連結リストの先頭に置いてあるやつも番兵ノードということがあります。
せっかくなので、dummy 抜きで書いてみますか?
Owner
Author
There was a problem hiding this comment.
そうなんですね!なるほどありがとうございます!
はい、dummyぬきでも実装してみます!
oda
reviewed
Jun 1, 2024
| メモリ使用量としては、再帰の深さ D*スタックフレームサイズ M とおおよそ見積もれる。 | ||
| 今回のケースでは再帰の深さは 100 | ||
| スタックフレームサイズは、int が 4byte、ListNode が 8byte (64 ビット JVM のとき)であると見積もると、int 変数が3つ、ListNode が3つなので、4*3+8\*3=36byte くらい? | ||
| JVM のデフォルトのスタックサイズは 1MB なので、1M/36byte=27K 回くらい再帰ができるということになる。 |
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.
問題URL:https://leetcode.com/problems/add-two-numbers/description/