Skip to content

Commit 22b9c0a

Browse files
committed
404
1 parent ad17c4f commit 22b9c0a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ Success is like pregnancy, Everybody congratulates you but nobody knows how many
7070
|-----|-------| -------- | ---- | ------|------------|---|-----|
7171
|110|[Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/#/description)| [Python [Yu]](./tree/Yu/110_isBalanced.py) | _O(N)_| _O(h)_ | Easy | ||
7272
|112|[Path Sum](https://leetcode.com/problems/path-sum/#/description)| [Python [Yu]](./tree/Yu/112_hasPathSum.py) | _O(N)_| _O(h)_ | Easy | |[中文讲解](https://www.youtube.com/watch?v=LgtcGjIuE18&feature=youtu.be)|
73+
|404|[Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/#/description)| [Python [Yu]](./tree/Yu/404_sum_of_Left_Leaves.py) | _O(N)_| _O(h)_ | Easy | ||
74+
75+
76+
7377

7478
## 4/26 Tasks (Tree Easy)
7579
| # | Title | Solution | Time | Space | Difficulty |Tag| Note|

tree/Yu/404_sum_of_Left_Leaves.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution(object):
2+
def sumOfLeftLeaves(self, root):
3+
"""
4+
:type root: TreeNode
5+
:rtype: int
6+
"""
7+
if not root:
8+
return 0
9+
10+
if root.left and root.left.left == None and root.left.right == None:
11+
return root.left.val + self.sumOfLeftLeaves(root.right)
12+
13+
left = self.sumOfLeftLeaves(root.left)
14+
right = self.sumOfLeftLeaves(root.right)
15+
16+
return left + right

0 commit comments

Comments
 (0)