[leetcode]404. Sum of Left Leaves左叶子之和

弄个flag记录是不是左节点就行

int res = 0;
    public int sumOfLeftLeaves(TreeNode root) {
        if (root==null) return res;
        leftSum(root,false);
        return res;
    }
    private void leftSum(TreeNode root,boolean flag)
    {
        if (root.left==null&&root.right==null&&flag)
            res+=root.val;
        if (root.left!=null)
            leftSum(root.left,true);
        if (root.right!=null)
            leftSum(root.right,false);
    }
原文地址:https://www.cnblogs.com/stAr-1/p/8375767.html