[LeetCode][Python3] 337. House Robber III

티스토리 메뉴 펼치기 댓글수0

프로그래밍/LeetCode

[LeetCode][Python3] 337. House Robber III

snoopybox
댓글수0

Problem :

https://leetcode.com/problems/house-robber-iii/


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 rob(selfroot):
        def find(node):
            if node:
                left = find(node.left)
                right = find(node.right)
                return (max(left) + max(right),
                        node.val + left[0] + right[0])
            return (00)

        return max(find(root))
맨위로

https://www.snoopybox.co.kr/2051

신고하기