diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md index e55981e2..ffcd2c8c 100644 --- a/problems/0404.左叶子之和.md +++ b/problems/0404.左叶子之和.md @@ -171,10 +171,10 @@ class Solution { int rightValue = sumOfLeftLeaves(root.right); // 右 int midValue = 0; - if (root.left != null && root.left.left == null && root.left.right == null) { // 中 + if (root.left != null && root.left.left == null && root.left.right == null) { midValue = root.left.val; } - int sum = midValue + leftValue + rightValue; + int sum = midValue + leftValue + rightValue; // 中 return sum; } } @@ -230,8 +230,8 @@ class Solution { ## Python -**递归** -```python +**递归后序遍历** +```python3 class Solution: def sumOfLeftLeaves(self, root: TreeNode) -> int: if not root: @@ -242,13 +242,13 @@ class Solution: cur_left_leaf_val = 0 if root.left and not root.left.left and not root.left.right: - cur_left_leaf_val = root.left.val # 中 + cur_left_leaf_val = root.left.val - return cur_left_leaf_val + left_left_leaves_sum + right_left_leaves_sum + return cur_left_leaf_val + left_left_leaves_sum + right_left_leaves_sum # 中 ``` **迭代** -```python +```python3 class Solution: def sumOfLeftLeaves(self, root: TreeNode) -> int: """