Simple Java without stack, queue


  • 0
    P
    public int sumOfLeftLeaves(TreeNode root) {
        int result = 0;
        if (root == null) {
            return result;
        }
        if (root.left != null && root.left.left == null && root.left.right == null) {
            result += root.left.val;
        }
        return result + sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
    }

Log in to reply
 

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