Invert Binary Tree

原创 2015年07月09日 23:15:52
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public TreeNode invertTree(TreeNode root) {
        if (root == null){
            return root;
        }
        TreeNode temp = root.right;
        root.right = root.left;
        root.left = temp;
        invertTree(root.right);
        invertTree(root.left);
        return root;
    }
}

PAT-PAT (Advanced Level) Practise 1102 Invert a Binary Tree (25)【三星级】

题目链接:http://www.patest.cn/contests/pat-a-practise/1102 题面: 1102. Invert a Binary Tree (25) ...

[leetcode] 226. Invert Binary Tree 解题报告

题目链接:https://leetcode.com/problems/invert-binary-tree/ Invert a binary tree. 4 / \ 2 ...

【PAT】1102. Invert a Binary Tree (25)

The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ...

LeetCode笔记:226. Invert Binary Tree

反转二叉树每个节点的左右子节点

1102.Invert a Binary Tree (25)[树的遍历]

1. 原题: https://www.patest.cn/contests/pat-a-practise/1102 2. 思路: 题意:树的遍历题。 给出一颗二叉树,输出反转后的层序和中序。 思路: ...

1102. Invert a Binary Tree 解析

按表建树, 然后层序按 先右子树再左子树的顺序进队列, 中序按 右中左的顺序遍历就是翻转后的。 #include #include #include #include #include ...

pat 1102. Invert a Binary Tree (25)

The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ...

leetcode 226 :Invert Binary Tree

题目: Invert a binary tree.4 / \ 2 7 / \ / \ 1 3 6 9to4 / \ 7 2 ...

LeetCode题解-226-Invert Binary Tree

尽管写LeetCode解答主要是为了自己整理思路,但是如果对您也正好有帮助,请点个赞给菜鸟一点鼓励吧 :-) 原题 解法分析 解法1使用了递归; 解法2使用了迭代法,为广度优先...

LintCode --invert-binary-tree(翻转二叉树)

LintCode --invert-binary-tree(翻转二叉树) 原题链接:http://www.lintcode.com/zh-cn/problem/invert-binary-tre...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Invert Binary Tree
举报原因:
原因补充:

(最多只允许输入30个字)