226. Invert Binary Tree--LeetCode Record

来源:互联网 发布:python mysql 回滚 编辑:程序博客网 时间:2024/06/05 23:48

这里写图片描述

/** * 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    }}
0 0
原创粉丝点击