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;
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

[LeetCode] Invert Binary Tree - 二叉树翻转系列问题

目录: Binary Tree Level Order Traversal - 二叉树层次遍历 BFS 题目背景是MaxHowell(他是苹果电脑最受欢迎的homebrew程序作者)去Google面试...

leetCode 226. Invert Binary Tree

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

leetcode-226. Invert Binary Tree c++ java

1、来源:226. Invert Binary Tree 2、题目: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 ...

1102. Invert a Binary Tree (25)

唯一注意一点,就是根结点这里并未给出,需要自己根据输入判断出来。 #include #include #include #include #include #include usi...

1102. Invert a Binary Tree (25)-PAT甲级真题

1102. Invert a Binary Tree (25) The following is from Max Howell @twitter: Google: 90% of ou...

LeetCode 226 Invert Binary Tree(转换二叉树)

翻译将下图中上面的二叉树转换为下面的形式,具体为每个左孩子节点和右孩子节点互换位置。原文如上图分析每次关于树的题目出错都在于边界条件上……所以这次仔细多想了一遍:void swapNode(TreeN...
  • NoMasp
  • NoMasp
  • 2015-12-27 12:31
  • 2496

A1102. Invert a Binary Tree (25)

A1102. Invert a Binary Tree (25)

LeetCode Invert Binary Tree OJ 刷题 算法

Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9to 4...

PAT (Advanced Level) 1102. Invert a Binary Tree (25) 解题报告

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

PAT甲 1102. Invert a Binary Tree (25)

The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrot...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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