226. Invert Binary Tree [LeetCode]

来源:互联网 发布:研究生小论文数据造假 编辑:程序博客网 时间:2024/06/03 10:59

Invert a binary tree.

     4   /   \  2     7 / \   / \1   3 6   9
to
     4   /   \  7     2 / \   / \9   6 3   1
Trivia:
This problem was inspired by this original tweet by Max Howell:
Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.

本题就是传说中的翻转二叉树。。题目意思简单明了。。实现也十分简单。。给出一个思路:先对root的左右子树交换,再对左右子树进行递归处理;递归的结束条件是root为null。

具体的java实现代码如下:


0 0
原创粉丝点击