Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ade452c

Browse files
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

Lines changed: 22 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /