Skip to content

Commit ade452c

Browse files
committed
404. Sum of Left Leaves
1 parent 7885414 commit ade452c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/404. Sum of Left Leaves.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 404. Sum of Left Leaves
3+
* https://leetcode.com/problems/sum-of-left-leaves/
4+
* Definition for a binary tree node.
5+
* function TreeNode(val) {
6+
* this.val = val;
7+
* this.left = this.right = null;
8+
* }
9+
*/
10+
/**
11+
* @param {TreeNode} root
12+
* @return {number}
13+
*/
14+
var sumOfLeftLeaves = function (root) {
15+
if (root === null) {
16+
return 0;
17+
}
18+
if (root.left !== null && root.left.left === null && root.left.right === null) {
19+
return root.left.val + sumOfLeftLeaves(root.right)
20+
}
21+
return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
22+
};

0 commit comments

Comments
 (0)