-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path513.py
More file actions
31 lines (27 loc) · 853 Bytes
/
Copy path513.py
File metadata and controls
31 lines (27 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def findBottomLeftValue(self, root):
"""
:type root: TreeNode
:rtype: int
"""
return self.res(root, 1)[0];
def res(self, root, dep):
if root.right == None and root.left == None:
return [root.val, dep];
if root.right == None:
return self.res(root.left, dep + 1);
if root.left == None:
return self.res(root.right, dep + 1);
else:
l = self.res(root.left, dep + 1);
r = self.res(root.right, dep + 1);
if l[1] < r[1]:
return r;
else:
return l;