Skip to content

Create Convert-Sorted-List-to-Binary-Search-Tree.md#15

Open
tshimosake wants to merge 2 commits intomasterfrom
tshimosake-patch-13
Open

Create Convert-Sorted-List-to-Binary-Search-Tree.md#15
tshimosake wants to merge 2 commits intomasterfrom
tshimosake-patch-13

Conversation

@tshimosake
Copy link
Copy Markdown
Owner

@tshimosake
Copy link
Copy Markdown
Owner Author

ほかの方のPRをよく見ると参照しているPRの数が4,5くらいである一方、私は一つ二つ見て満足してしまっているので改めたい...

# 再帰ケース
mid = len(nums) // 2
res = TreeNode(nums[mid])
res.left = self.sortedArrayToBST(nums[:mid])
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.

ご指摘ありがとうございます!追記しました!

return res
```

2回目。特に直すところは思いつかなかったので省略する(mid を mid_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.

名前はいいですが、スライスを取るとコピーが作られるというのは意識してもいいでしょう。

完走した人から気に入ったコードを書く人を少し見繕っておくといいかと思いますよ。

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.

ご指摘ありがとうございます!追記しました!

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