404. Sum of Left Leaves

题目其实指的是left non-inner-node。。

然后就没啥了,BFS DFS应该都可以。。BFS可能麻烦点。
DFS就是遍历前判定下,满足条件的恰好不需要继续go further from that one。。

public class Solution 
{
    
    public int sumOfLeftLeaves(TreeNode root) 
    {
        if(root == null) return 0;
        
        if(root.left!=null && root.left.left == null && root.left.right == null) 
            return root.left.val + sumOfLeftLeaves(root.right);
        else return sumOfLeftLeaves(root.left)+sumOfLeftLeaves(root.right);
        
    }
}
posted @ 2016-09-26 07:22  哇呀呀..生气啦~  阅读(121)  评论(0)    收藏  举报