当前位置:网站首页>[leetcode refers to offer 27. Image of binary tree (simple)]

[leetcode refers to offer 27. Image of binary tree (simple)]

2022-04-23 21:02:00 Minaldo7

subject :

 Insert picture description here

source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .

The problem solving process :

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */
class Solution {
    
    public TreeNode mirrorTree(TreeNode root) {
    
        
        if(root == null) return root;
        
        TreeNode temp = root.right ;
        root.right = root.left;
        root.left = temp ;

        mirrorTree(root.left);
        mirrorTree(root.right);
        return root;
    }
}

Execution results :

 Insert picture description here

版权声明
本文为[Minaldo7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/111/202204210544479652.html