Skip to content

108. Convert Sorted Array to Binary Search Tree#26

Open
xbam326 wants to merge 3 commits into
mainfrom
108
Open

108. Convert Sorted Array to Binary Search Tree#26
xbam326 wants to merge 3 commits into
mainfrom
108

Conversation

@xbam326
Copy link
Copy Markdown
Owner

@xbam326 xbam326 commented Feb 8, 2026

- https://github.com/05ryt31/leetcode/pull/15
- コードの出力は自分と似ていたので感覚は近そう
- https://github.com/mamo3gr/arai60/pull/23/changes
- 配列の範囲の終点を扱うのに、開区間と閉区間の方がある(始点は閉区間でいいだろう)。Pythonのインデックスに従うなら開区間だが、閉区間の方が(個人的には)扱いやすくバグのリスクが減らせそう。「リーダブルコードで」、開区間なら `begin, end`, 閉区間なら `start, last` を使う、という命名を思い出す。→書いてみたら「中央の要素を抜いた、配列の左右がそれぞれ存在するかどうか」の分岐条件が違うだけみたいだった。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

半開区間なら begin, end をよく見かけるように感じます。 C++ のイテレーターはこのパターンです。

# self.right = right
class Solution:
def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]:
binary_root = None
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

他と区別する必要がないため、 binary_ という接頭辞は省略しても十分伝わると思いました。

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.

2 participants