mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
28 lines
457 B
Go
28 lines
457 B
Go
package leetcode
|
|
|
|
import (
|
|
"github.com/halfrost/LeetCode-Go/structures"
|
|
)
|
|
|
|
// TreeNode define
|
|
type TreeNode = structures.TreeNode
|
|
|
|
/**
|
|
* Definition for a binary tree node.
|
|
* type TreeNode struct {
|
|
* Val int
|
|
* Left *TreeNode
|
|
* Right *TreeNode
|
|
* }
|
|
*/
|
|
|
|
func invertTree(root *TreeNode) *TreeNode {
|
|
if root == nil {
|
|
return nil
|
|
}
|
|
invertTree(root.Left)
|
|
invertTree(root.Right)
|
|
root.Left, root.Right = root.Right, root.Left
|
|
return root
|
|
}
|