Java Clean and Easy Solution


  • 0
    A
    public int sumOfLeftLeaves(TreeNode root) {
            
            //Root Null
            if(root == null){
                
                return 0;
            }
            
            //Total Sum
            int total = 0;
            
            //isLeaf
            if(root.left!=null && root.left.left == null && root.left.right == null){
                total+= root.left.val+ sumOfLeftLeaves(root.right);
            }
            else{
                total+=sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
                
            }
            return total;
        }
    
    

Log in to reply
 

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