/**
* Definition for a binary tree node.
* public class TreeNode {
* public var val: Int
* public var left: TreeNode?
* public var right: TreeNode?
* public init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
* }
* }
*/
class Solution {
func invertTree(root: TreeNode?) -> TreeNode? {
if root == nil {
return nil
}
let swapNode = invertTree(root?.left)
root?.left = invertTree(root?.right)
root?.right = swapNode
return root
}
}
226. Invert Binary Tree--LeetCode Record
最新推荐文章于 2024-07-30 19:30:52 发布