int res = 0;
public int sumOfLeftLeaves(TreeNode root) {
if (root == null) {
return res;
}
if (root.left != null && root.left.left == null && root.left.right == null) {
res += root.left.val;
} else if (root.left != null) {
sumOfLeftLeaves(root.left);
}
sumOfLeftLeaves(root.right);
return res;
}
Leetcode404:左叶子之和
最新推荐文章于 2024-05-15 20:13:50 发布