leetcode-226:翻转二叉树

翻转一棵二叉树。

解:
翻转二叉树,就是把左节点改为右节点,然后把右节点改为左节点,明显就是个递归嘛~


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

solution

你可能感兴趣的:(leetcode-226:翻转二叉树)