Recursive Java Solution


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

Log in to reply
 

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