Skip to content

103. Binary Tree Zigzag Level Order Traversal#26

Open
seal-azarashi wants to merge 3 commits into
mainfrom
binary-tree-zigzag-level-order-traversal
Open

103. Binary Tree Zigzag Level Order Traversal#26
seal-azarashi wants to merge 3 commits into
mainfrom
binary-tree-zigzag-level-order-traversal

Conversation

@seal-azarashi
Copy link
Copy Markdown
Owner

seal_azarashi added 2 commits September 21, 2024 00:25
}

if (isReversed) {
valsInCurrentLevel = valsInCurrentLevel.isReversed();
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

@fhiyo fhiyo left a comment

Choose a reason for hiding this comment

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

良いと思います。zigzagLevelOrderValsの要素をArrayListにして、かつreversed()を使わないで書いてみてもいいかもしれません。

@Yoshiki-Iwasa
Copy link
Copy Markdown

良いと思います


### Step 1 を読みやすくする

オーバーヘッドを少しでも減らそうと工夫していましたが、それで削減できるのは微々たるものなので、読みやすさをとってレベルごとの処理の最後に reversed() メソッドを呼ぶように変えました。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

はい。思っているよりも、オーバーヘッドを改善した気になっていてもあんまり変わっていないことが多いです。
気になるようだったら、Profile を取ってみましょう。

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.

5 participants