[LeetCode][Python3] 124. Binary Tree Maximum Path Sum
2019. 4. 20. 23:49 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/binary-tree-maximum-path-sum/
My Solution :
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def maxPathSum(self, root: TreeNode) -> int:
def find(root):
if root:
left = find(root.left)
right = find(root.right)
self.ans = max(self.ans, root.val + left + right)
return max(0, root.val + max(left, right))
return 0
self.ans = root.val
find(root)
return self.ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 50. Pow(x, n) (0) | 2019.04.24 |
---|---|
[LeetCode][Python3] 212. Word Search II (0) | 2019.04.24 |
[LeetCode][Python3] 41. First Missing Positive (0) | 2019.04.23 |
[LeetCode][Python3] 152. Maximum Product Subarray (0) | 2019.04.22 |
[LeetCode][Python3] 322. Coin Change (0) | 2019.04.20 |
[LeetCode][Python3] 54. Spiral Matrix (0) | 2019.04.18 |
[LeetCode][Python3] 76. Minimum Window Substring (0) | 2019.04.16 |
[LeetCode][Python3] 84. Largest Rectangle in Histogram (0) | 2019.04.15 |
최근에 달린 댓글 최근에 달린 댓글