Skip to content

Commit 3435324

Browse files
authored
Create binary_tree_maximum_node.py
1 parent 23aad21 commit 3435324

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

binary_tree_maximum_node.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# coding: utf-8
2+
3+
class Solution:
4+
# @param {TreeNode} root the root of binary tree
5+
# @return {TreeNode} the max node
6+
def maxNode(self, root):
7+
if root:
8+
_max = root
9+
if root.left:
10+
left_max = self.maxNode(root.left)
11+
if _max.val < left_max.val:
12+
_max = left_max
13+
if root.right:
14+
right_max = self.maxNode(root.right)
15+
if _max.val < right_max.val:
16+
_max = right_max
17+
return _max
18+
19+
# entry: http://www.lintcode.com/zh-cn/problem/binary-tree-maximum-node/

0 commit comments

Comments
 (0)