Update 0513.找树左下角的值.md

更改变量名称
This commit is contained in:
Kelvin
2021-07-29 13:50:56 -04:00
parent 49d55fb1c8
commit 1dd4a529fc

View File

@ -280,31 +280,25 @@ Python
class Solution:
def findBottomLeftValue(self, root: TreeNode) -> int:
max_depth = -float("INF")
max_left_value = -float("INF")
def __traversal(root, left_len):
nonlocal max_depth, max_left_value
leftmost_val = 0
def __traverse(root, cur_depth):
nonlocal max_depth, leftmost_val
if not root.left and not root.right:
if left_len > max_depth:
max_depth = left_len
max_left_value = root.val
return
if cur_depth > max_depth:
max_depth = cur_depth
leftmost_val = root.val
if root.left:
left_len += 1
__traversal(root.left, left_len)
left_len -= 1
cur_depth += 1
__traverse(root.left, cur_depth)
cur_depth -= 1
if root.right:
left_len += 1
__traversal(root.right, left_len)
left_len -= 1
return
__traversal(root, 0)
cur_depth += 1
__traverse(root.right, cur_depth)
cur_depth -= 1
return max_left_value
__traverse(root, 0)
return leftmost_val
```
**迭代 - 层序遍历**
```python