Skip to content

108-convert-sorted-array-to-binary-search-tree#15

Open
05ryt31 wants to merge 1 commit intomainfrom
feat/108
Open

108-convert-sorted-array-to-binary-search-tree#15
05ryt31 wants to merge 1 commit intomainfrom
feat/108

Conversation

@05ryt31
Copy link
Owner

@05ryt31 05ryt31 commented Jan 11, 2026

問題リンク

https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/description/

問題文の概要

Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

次に解く予定の問題

https://leetcode.com/problems/path-sum/description/

@@ -0,0 +1,20 @@
# 最適解のコード
Copy link

Choose a reason for hiding this comment

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

自分にしっくり来る形で整理されたもの、くらいのニュアンスだと思うのですが、他の人のコードやコメント集を見てさらに選択肢の幅を広げたり、パフォーマンスなどの他の観点でも考察してみるとより味わえると思います。

Copy link

Choose a reason for hiding this comment

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

感覚を一致させることが最終ゴールとは思いますが、やり方は色々だろうと思います。

(人のコードを読む方に重点を置くといいかもしれません。)

Copy link
Owner Author

@05ryt31 05ryt31 Jan 12, 2026

Choose a reason for hiding this comment

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

毎度Google Docsで該当の問題のコメント集に目は通すのですが、他の人のコードももっと見にいくよう心がけます。
ちなみにここの手順ってどのようにされていますか?
特に他の人が書いているコードの探し方などが気になります。
@mamo3gr
cc @oda

Choose a reason for hiding this comment

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

横から失礼します。
決まった手順があるわけではないと思いますが、私はDiscordの レビュー依頼チャンネル で自分の解いた問題を検索して、他の方々のpull requests を見るようにしています。

Copy link

Choose a reason for hiding this comment

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

私も、Discordのレビュー依頼チャンネルを問題名で検索して、同じ言語のPRを直近3-5個見るようにしています(実は別な言語を見たほうが更に学びになりそうですが、実践できていません)。
繰り返すうち、考察がしっかりしていたり、好みが自分と似ていたりしている人を見つけるので、その人のPRは必ず入れるようにしています。

Copy link
Owner Author

Choose a reason for hiding this comment

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

お二人ともありがとうございます!これから実践していこうと思います。

Copy link

Choose a reason for hiding this comment

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

完走した人から見繕っておくといいように思います。

「in: レビュー依頼 55」で Discord 検索するとだいたい完走した人がでてきますね。

Copy link

@huyfififi huyfififi left a comment

Choose a reason for hiding this comment

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

👍

return None

middle = (left + right) // 2
root = TreeNode(nums[middle])

Choose a reason for hiding this comment

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

私は TreeNode が中途半端な状態でいるよりも、TreeNodeのインスタンスを作るときにそのままval, left, rightを全て渡してしまう方が好みですが、趣味の範囲だと思います。

return TreeNode(
    val=nums[middle],
    left=buildBST(left, middle - 1),
    right=buildBST(middle + 1, right),
)

Copy link
Owner Author

Choose a reason for hiding this comment

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

確かに、このように書いた方が綺麗にまとまっていて読みやすいように感じました

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.

4 participants