1. 程式人生 > >113. Path Sum II 輸出每個具體路徑

113. Path Sum II 輸出每個具體路徑

程序 不用 time fun 優化 ret path sum deb 叠代

[抄題]:

Given a binary tree and a sum, find all root-to-leaf paths where each path‘s sum equals the given sum.

Note: A leaf is a node with no children.

Example:

Given the below binary tree and sum = 22,

      5
     /     4   8
   /   /   11  13  4
 /  \    / 7    2  5   1

Return:

[
   [5,4,11,2],
   [5,8,4,5]
]

[暴力解法]:

時間分析:

空間分析:

[優化後]:

時間分析:

空間分析:

[奇葩輸出條件]:

[奇葩corner case]:

[思維問題]:

[英文數據結構或算法,為什麽不用別的數據結構或算法]:

[一句話思路]:

[輸入量]:空: 正常情況:特大:特小:程序裏處理到的特殊情況:異常情況(不合法不合理的輸入):

[畫圖]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分鐘肉眼debug的結果]:

[總結]:

[復雜度]:Time complexity: O() Space complexity: O()

[算法思想:叠代/遞歸/分治/貪心]:

[關鍵模板化代碼]:

[其他解法]:

[Follow Up]:

[LC給出的題目變變變]:

[代碼風格] :

[是否頭一次寫此類driver funcion的代碼] :

[潛臺詞] :

113. Path Sum II 輸出每個具體路徑