LeetCode之226. Invert Binary Tree

-------------------------------------

反转树的基本操作。

可是下面那句话是什么鬼啊,这么牛掰的人都会有这种遭遇,确实抚慰了一点最近面试被拒的忧伤.....悲伤

AC代码:

/**
 * 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 null;
        
        TreeNode t=root.left;
        root.left=invertTree(root.right);
        root.right=invertTree(t);
        
        return root;
    }
}

题目来源: https://leetcode.com/problems/invert-binary-tree/

原文地址:https://www.cnblogs.com/cc11001100/p/5991871.html