public int sumOfLeftLeaves(TreeNode root) {
if(root == null) return 0;
int ans = 0;
if(root.left != null) {
if(root.left.left == null && root.left.right == null) ans += root.left.val;
else ans += sumOfLeftLeaves(root.left);
}
ans += sumOfLeftLeaves(root.right);
return ans;
}
404. Sum of Left Leaves
最新推荐文章于 2020-07-13 01:21:02 发布