/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode invertTree(TreeNode root) {
if (root == null){
return root;
}
TreeNode temp = root.right;
root.right = root.left;
root.left = temp;
invertTree(root.right);
invertTree(root.left);
return root;
}
}
Invert Binary Tree
最新推荐文章于 2022-11-04 16:22:05 发布