class Solution {
public TreeNode invertTree(TreeNode root) {
invert(root);
return root;
}
public void invert(TreeNode root){
if(root == null)
return;
invert(root.left);
invert(root.right);
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
}
}
leetcode226. 翻转二叉树
最新推荐文章于 2024-08-15 05:02:54 发布