Lintcode 175. 翻转二叉树

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

递归那么好为什么不用递归啊...我才不会被你骗...(其实是因为用惯了递归啰嗦的循环反倒不会写了...o(╯□╰)o)

AC代码:

/**
 * Definition of TreeNode:
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left, right;
 *     public TreeNode(int val) {
 *         this.val = val;
 *         this.left = this.right = null;
 *     }
 * }
 */
public class Solution {
    /**
     * @param root: a TreeNode, the root of the binary tree
     * @return: nothing
     */
    public void invertBinaryTree(TreeNode root) {
        if(root==null) return ;
        TreeNode t=root.left;
        root.left=root.right;
        root.right=t;
        invertBinaryTree(root.left);
        invertBinaryTree(root.right);
    }
}

题目来源: http://www.lintcode.com/zh-cn/problem/invert-binary-tree/

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