1 Star 1 Fork 0

masx200 / leetcode-TreeNode-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
queue.go 642 Bytes
一键复制 编辑 原始数据 按行查看 历史
egregors 提交于 2022-02-01 12:04 . dev: cleanup receivers
package treenode
// NodeQueue is a simple queue of TreeNode pointers
type NodeQueue []*TreeNode
// IsEmpty returns true if the queue is empty
func (q *NodeQueue) IsEmpty() bool { return len(*q) == 0 }
// Push adds a nodes to the end of the queue. You can push a few nodes at a time.
// They will be added like a "tail":
// ] q == [a, b, c] => q.Push(d, e, f) -> q == [a, b, c, d, e, f]
func (q *NodeQueue) Push(nodes ...*TreeNode) { *q = append(*q, nodes...) }
// Pop removes the first node from the queue and returns it.
func (q *NodeQueue) Pop() *TreeNode {
if !q.IsEmpty() {
n := (*q)[0]
*q = (*q)[1:]
return n
}
return nil
}
Go
1
https://gitee.com/masx200/leetcode-TreeNode-go.git
git@gitee.com:masx200/leetcode-TreeNode-go.git
masx200
leetcode-TreeNode-go
leetcode-TreeNode-go
v1.0.4

搜索帮助