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.
解法1:Recursion O(N) Time
二叉树很自然的想到用递归的办法解决。这里的难点是要记录每一个节点是否为Left child/right child,为此我们需要有一个helper函数来记录。根据OA的结果,root是算作非左子树的。
C++
Java