翻转二叉树 (翻转二叉树)

 

思路:

// @Title: 翻转二叉树 (翻转二叉树)
// @Author: qisiii
// @Date: 2022-02-20 22:35:59
// @Runtime: 0 ms
// @Memory: 38.8 MB
// @comment: 
// @flag: 
/**
 * 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 null;
        }
        TreeNode temp=root.left;
        root.left=root.right;
        root.right=temp; 
        mirrorTree(root.left);
        mirrorTree(root.right);
        return root;
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18