Leetcode-标签为Tree 226. Invert Binary Tree

来源:互联网 发布:个人理财软件 编辑:程序博客网 时间:2024/05/22 06:47

原题

Invert a binary tree.

     4   /   \  2     7 / \   / \1   3 6   9

to

     4   /   \  7     2 / \   / \9   6 3   1

代码分析

反转二叉树

代码实现

        public TreeNode InvertTree(TreeNode root)        {            if (root == null)                return null;            var tmp = root.left;            root.left = root.right;            root.right = tmp;            InvertTree(root.left);            InvertTree(root.right);            return root;        }
1 0