Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 1.46 KB

0226-invert-binary-tree.adoc

File metadata and controls

68 lines (51 loc) · 1.46 KB

226. Invert Binary Tree

{leetcode}/problems/invert-binary-tree/[LeetCode - Invert Binary Tree^]

Invert a binary tree.

Example:
Input:

     4
   /   \
  2     7
 / \   / \
1   3 6   9

Output:
     4
   /   \
  7     2
 / \   / \
9   6 3   1

Trivia:

This problem was inspired by this original tweet by Max Howell (@mxcl):

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.

思路分析

D瓜哥也不会做这道题,现在可以说跟大神一个水平了,😆

其实,思路很简单:就是递归地反转每棵树即可。

{image_attr}
一刷
link:{sourcedir}/_0226_InvertBinaryTree.java[role=include]
二刷
link:{sourcedir}/_0226_InvertBinaryTree_2.java[role=include]