Find the sum of all left leaves in a given binary tree.
Example:
3
/ \
9 20
/ \
15 7
There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
<Solution>通常 tree 的問題,不是 DFS 就是 BFS
那實作的方式,就有 iterative 和 recursive 兩種
這邊就按照提意來寫就可以
code 如下
C++,Iterative
C++,Recursive
沒有留言:
張貼留言