* Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class{ publicintsumOfLeftLeaves(TreeNode root){ if (root == null) return0; int sum = 0; if (root.left != null && root.left.left==null && root.left.right==null) { sum += root.left.val; } sum += sumOfLeftLeaves(root.left); sum += sumOfLeftLeaves(root.right); return sum; } }
近期评论