Skip to content

Conversation

@rihib
Copy link
Owner

@rihib rihib commented Dec 22, 2024

Right: sortedArrayToBSTHalfOpenHelper(nums, mid+1, right),
}
}

Copy link

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)
Copy link

Choose a reason for hiding this comment

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

container/listを使ったことがなかったので質問させてください

  1. .(bstElement)と書いているということはqueueにはbstElement以外の型の要素も入り得るということですか?
  2. queue[1:]でRemoveを、appendでPushBackを行えるのでキューとしてcontainer/listを使うメリットがあるのかよくわからなかったです。かといってデメリットも特に思いつきません。ここら辺のメリデリってどんな感じですか?Go 言語標準ライブラリの container/list を deque として使ってみたによるとdoubly-linked-listなのでdequeueとして使う分にはメリットがありそうです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants