My Java Solution


  • 0
    H

    public int sumOfLeftLeaves(TreeNode root) {
    if(root == null)
    return 0;

        int ret = 0;
        if(root.left != null) {
            if (root.left.left == null && root.left.right == null)
                ret += root.left.val;
            else
                ret += sumOfLeftLeaves(root.left);
        }
        if(root.right != null)
            ret += sumOfLeftLeaves(root.right);
        return ret;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.