226. 翻转二叉树

226. 翻转二叉树

226. 翻转二叉树

    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        invertTree(root.left);
        invertTree(root.right);
        swapChildren(root);
        return root;
    }

    private void swapChildren(TreeNode root) {
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;
    }
}
上一篇:中间件部署


下一篇:第六章:(1)Synchronized 锁的八种情况