LeetCode基础--二叉树--反转左右子树

来源:互联网 发布:奇葩说范湉湉长相 知乎 编辑:程序博客网 时间:2024/06/08 16:48

题目描述:
反转二叉树的左右子树。

实现:

public class Solution {    public TreeNode InvertTree(TreeNode root) {        if(root == null)        {            return null;        }        TreeNode tmp = root.left;        root.left = InvertTree(root.right);        root.right = InvertTree(tmp);        return root;    }}
原创粉丝点击