My recursion java solution.


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

Log in to reply
 

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