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