func (n *Node) MaxOfLevels() []int {
	maxs := make([]int, 0)
	queue := make([]*Node, 0)
	var lvlSize int
	var max int
	var curr *Node

	queue = append(queue, n)

	for len(queue) > 0 {
		lvlSize = len(queue)
		max = -1 << 63

		for i := 0; i < lvlSize; i++ {
			curr = queue[0]
			queue = queue[1:]

			if curr.right != nil {
				queue = append(queue, curr.right)
			}

			if curr.left != nil {
				queue = append(queue, curr.left)
			}

			if max < curr.value {
				max = curr.value
			}
		}

		maxs = append(maxs, max)
		max = 0
	}

	return maxs
}
// MaxOfLevels gets the max of each level of a binary tree
MaxOfLevels gets the max of each level of a binary tree
// MaxOfLevels gets the max of each level of a binary tree
func (n *Node) MaxOfLevels() []int {
	maxs := make([]int, 0)
	queue := make([]*Node, 0)
	var lvlSize int
	var max int
	var curr *Node
	queue = append(queue, n)
	for len(queue) > 0 {
		lvlSize = len(queue)
		max = -1 << 63
		for i := 0; i < lvlSize; i++ {
			curr = queue[0]
			queue = queue[1:]
			if curr.right != nil {
				queue = append(queue, curr.right)
			}
			if curr.left != nil {
				queue = append(queue, curr.left)
			}
			if max < curr.value {
				max = curr.value
			}
		}
		maxs = append(maxs, max)
		max = 0
	}
	return maxs
}
func ( n * Node ) MaxOfLevels ( ) [ ] int { maxs := make ( [ ] int , 0 ) queue := make ( [ ] * Node , 0 ) var lvlSize int var max int var curr * Node queue = append ( queue , n ) for len ( queue ) > 0 { lvlSize = len ( queue ) max = - 1 << 63 for i := 0 ; i < lvlSize ; i ++ { curr = queue [ 0 ] queue = queue [ 1 : ] if curr . right != nil { queue = append ( queue , curr . right ) } if curr . left != nil { queue = append ( queue , curr . left ) } if max < curr . value { max = curr . value } } maxs = append ( maxs , max ) max = 0 } return maxs }
MaxOfLevels gets the max of each level of a binary tree
MaxOfLevels gets the max of each level of a binary tree