Simple Java Solution:)


  • 0
    S
      public int sumOfLeftLeaves(TreeNode root) {
            if(root == null) return 0;
            return sumOfLeftLeaves(root.left, true) + sumOfLeftLeaves(root.right, false);
        }
        
        public int sumOfLeftLeaves(TreeNode root, Boolean isLeft) {
            if(root == null) {
                return 0;
            }
            
            if(isLeft && root.left == null && root.right == null) {
                return root.val;
            }
            return sumOfLeftLeaves(root.left, true) + sumOfLeftLeaves(root.right, false);
        }

Log in to reply
 

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