226.Invert Binary Tree

/**
 * 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 tem=root.left;
        root.left=root.right;
        root.right=tem;
        
        invertTree(root.left);
        invertTree(root.right);
        
        return root;
        
    }
}

 

相关文章:

  • 2021-06-16
  • 2022-02-14
  • 2021-12-20
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
猜你喜欢
  • 2021-09-01
  • 2021-09-16
  • 2021-08-16
相关资源
相似解决方案