Fork me on GitHub

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/

posted @ 2016-10-24 09:50  CC11001100  阅读(222)  评论(0编辑  收藏  举报