mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0513.找树左下角的值.md
This commit is contained in:
@ -274,8 +274,28 @@ class Solution {
|
|||||||
|
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
//递归法
|
||||||
|
# Definition for a binary tree node.
|
||||||
|
# class TreeNode:
|
||||||
|
# def __init__(self, val=0, left=None, right=None):
|
||||||
|
# self.val = val
|
||||||
|
# self.left = left
|
||||||
|
# self.right = right
|
||||||
|
class Solution:
|
||||||
|
def findBottomLeftValue(self, root: TreeNode) -> int:
|
||||||
|
depth=0
|
||||||
|
self.res=[]
|
||||||
|
def level(root,depth):
|
||||||
|
if not root:return
|
||||||
|
if depth==len(self.res):
|
||||||
|
self.res.append([])
|
||||||
|
self.res[depth].append(root.val)
|
||||||
|
level(root.left,depth+1)
|
||||||
|
level(root.right,depth+1)
|
||||||
|
level(root,depth)
|
||||||
|
return self.res[-1][0]
|
||||||
|
```
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user