目錄:
1.invert binary tree - 二叉樹翻轉 [遞歸]
題目概述:
invert a binary tree.
to
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。
我的代碼:
其他代碼:
推薦閱讀和采用二叉樹非遞歸層次周遊算法實作如下。
其他題目: