/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode invertTree(TreeNode root) {
if(root == null){
return null;
}
TreeNode nLeft = root.left;
root.left = invertTree(root.right);
root.right = invertTree(nLeft);
return root;
}
}
算法应用(一)-翻转二叉树(递归算法)
最新推荐文章于 2024-11-05 01:41:28 发布