Accepted Simple java solution using helper


  • 0
    F
    public class Solution {
        int sum=0;
        public int sumOfLeftLeaves(TreeNode root) {
            sumHelper(root);
            return sum;
        }
        public void sumHelper(TreeNode root){
            if(root==null)
                return;
            if(root.left!=null && root.left.left==null && root.left.right==null)
                sum+=root.left.val;
            sumHelper(root.left);
            sumHelper(root.right);
        }
    }
    

Log in to reply
 

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