-
Notifications
You must be signed in to change notification settings - Fork 0
Convert Sorted Array to Binary Search Tree #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Counting Bits
Product of Array Except Self
Right: sortedArrayToBSTHalfOpenHelper(nums, mid+1, right), | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この stack queue を使った実装 TreeNode の初期化が重複している感覚があります。
ポインターのポインターを使うとなくせますね。
https://discord.com/channels/1084280443945353267/1262688866326941718/1298575468353556501
queue := list.New() | ||
queue.PushBack(bstElement{root, nums[:midIndex], nums[midIndex+1:]}) | ||
for queue.Len() > 0 { | ||
e := queue.Remove(queue.Front()).(bstElement) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
container/listを使ったことがなかったので質問させてください
.(bstElement)
と書いているということはqueueにはbstElement以外の型の要素も入り得るということですか?- queue[1:]でRemoveを、appendでPushBackを行えるのでキューとしてcontainer/listを使うメリットがあるのかよくわからなかったです。かといってデメリットも特に思いつきません。ここら辺のメリデリってどんな感じですか?Go 言語標準ライブラリの container/list を deque として使ってみたによるとdoubly-linked-listなのでdequeueとして使う分にはメリットがありそうです。
Convert Sorted Array to Binary Search Treeを解きました。レビューをお願いします。
問題:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
言語:Go
hayashi-ay/leetcode#29
sakupan102/arai60-practice#25
Mike0121/LeetCode#13
fhiyo/leetcode#26
Yoshiki-Iwasa/Arai60#28
kazukiii/leetcode#25
TORUS0818/leetcode#26
Ryotaro25/leetcode_first60#26
goto-untrapped/Arai60#48
seal-azarashi/leetcode#23
SuperHotDogCat/coding-interview#40
hroc135/leetcode#23