LintCode翻转二叉树

/**
 * 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) {
        // write your code here
       if(root==null)
        return;
       invertBinaryTree(root.left);
       invertBinaryTree(root.right);
       swap(root);
    }
    public void swap(TreeNode root)
    {
        TreeNode temp=root.left;
        root.left=root.right;
        root.right=temp;
    }
}

 

posted @ 2017-09-07 17:54  temporary  阅读(105)  评论(0编辑  收藏  举报