- 递归
class Solution {
public TreeNode invertTree(TreeNode root) {
if(root == null) return root;
TreeNode l = invertTree(root.left), r = invertTree(root.right);
root.left = r; root.right = l;
return root;
}
}
标签:leetcode226,TreeNode,invertTree,二叉树,root,翻转
From: https://www.cnblogs.com/xzh-yyds/p/16625548.html