invert_binary_tree

  • 2022-12-14
  • 浏览 (523)

invert_binary_tree.go 源码

package leetcode

// 翻转二叉树

// 递归
func invertTree(root *TreeNode) *TreeNode {
	if root == nil {
		return root
	}
	root.Left, root.Right = root.Right, root.Left
	invertTree(root.Right)
	invertTree(root.Left)
	return root
}

你可能感兴趣的文章

binary_tree_inorder_traversal

binary_tree_level_order_traversal

binary_tree_postorder_traversal

0  赞