github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/algorithm/leetcode/invert-binary-tree_test.go (about) 1 package leetcode 2 3 // 226. 翻转二叉树 4 // https://leetcode-cn.com/problems/invert-binary-tree/ 5 6 /** 7 * Definition for a binary tree node. 8 * type TreeNode struct { 9 * Val int 10 * Left *TreeNode 11 * Right *TreeNode 12 * } 13 */ 14 type TreeNode struct { 15 Val int 16 Left *TreeNode 17 Right *TreeNode 18 } 19 20 func invertTree(root *TreeNode) *TreeNode { 21 if root == nil { 22 return nil 23 } 24 root.Left, root.Right = invertTree(root.Right), invertTree(root.Left) 25 return root 26 }