弄个flag记录是不是左节点就行
int res = 0; public int sumOfLeftLeaves(TreeNode root) { if (root==null) return res; leftSum(root,false); return res; } private void leftSum(TreeNode root,boolean flag) { if (root.left==null&&root.right==null&&flag) res+=root.val; if (root.left!=null) leftSum(root.left,true); if (root.right!=null) leftSum(root.right,false); }