forked from yingl/LintCodeInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_tree_maximum_node.py
More file actions
19 lines (17 loc) · 611 Bytes
/
binary_tree_maximum_node.py
File metadata and controls
19 lines (17 loc) · 611 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# coding: utf-8
class Solution:
# @param {TreeNode} root the root of binary tree
# @return {TreeNode} the max node
def maxNode(self, root):
if root:
_max = root
if root.left:
left_max = self.maxNode(root.left)
if _max.val < left_max.val:
_max = left_max
if root.right:
right_max = self.maxNode(root.right)
if _max.val < right_max.val:
_max = right_max
return _max
# entry: http://www.lintcode.com/zh-cn/problem/binary-tree-maximum-node/