Skip to content

108. Convert Sorted Array to Binary Tree#18

Open
hiro111208 wants to merge 1 commit into
mainfrom
108-convert-sorted-array-to-binary-search-tree
Open

108. Convert Sorted Array to Binary Tree#18
hiro111208 wants to merge 1 commit into
mainfrom
108-convert-sorted-array-to-binary-search-tree

Conversation

@hiro111208
Copy link
Copy Markdown
Owner

Comment thread step2.md
if l > r:
return None
middle_index = (l + r) // 2
root = TreeNode(nums[middle_index])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ここはnodeでもいいかもしれないですね

Comment thread step2.md
root.left = helper(l, middle_index - 1)
root.right = helper(middle_index + 1, r)
return root
return helper(0, len(nums) - 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

helperを使ってうまくスライスを避けているのがいいなと思いました。

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.

3 participants