Easy Java Solution


  • 0
    J
    public class Solution {
        
        int count;
        public int sumOfLeftLeaves(TreeNode root) {
            count=0;
            if(root==null) return count;
           
            helper(root,false);
            return count;
            
        }
        
        public void helper(TreeNode root,boolean isLeft)
        {
            if(root.left==null && root.right==null){
                
                if(isLeft)count+=root.val;
                return;
            }
            
            if(root.left!=null) helper(root.left,true);
            if(root.right!=null) helper(root.right,false);
    
        }
    }
    

Log in to reply
 

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