[LeetCode] Invert Binary Tree - 二叉树翻转系列问题
生活随笔
收集整理的這篇文章主要介紹了
[LeetCode] Invert Binary Tree - 二叉树翻转系列问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄:
1.Invert Binary Tree - 二叉樹翻轉 [遞歸]
題目概述:
1.Invert Binary Tree - 二叉樹翻轉 [遞歸]
題目概述:
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.
題目分析:
? ? ? ? 題目背景是MaxHowell(他是蘋果電腦最受歡迎的homebrew程序作者)去Google面試,面試官說:“雖然在Google有90%的工程師用你寫的Homebrew,但是你居然不能再白板上寫出翻轉二叉樹的代碼,所以滾帶吧”!
? ? ? ? 該題最初想法就是通過遞歸依次交換左右結點,但是想得太多,如“是否需要再建一顆樹”、“是否需要引入隊列或BFS”,最終沒有AC。
我的代碼:
其他代碼:
? ? ? ? 推薦閱讀和采用二叉樹非遞歸層次遍歷算法實現如下。
? ? ? ??你會翻轉二叉樹嗎?--談程序員的招聘
? ? ? ? http://blog.csdn.net/sunao2002002/article/details/46482559
其他題目:
(By:Eastmount 2015-9-12 凌晨5點半? ?http://blog.csdn.net/eastmount/)
總結
以上是生活随笔為你收集整理的[LeetCode] Invert Binary Tree - 二叉树翻转系列问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [LeetCode] Binary Tr
- 下一篇: [LeetCode] Number of