Class Solution
java.lang.Object
g0301_0400.s0337_house_robber_iii.Solution
337 - House Robber III.<p>Medium</p>
<p>The thief has found himself a new place for his thievery again. There is only one entrance to this area, called <code>root</code>.</p>
<p>Besides the <code>root</code>, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if <strong>two directly-linked houses were broken into on the same night</strong>.</p>
<p>Given the <code>root</code> of the binary tree, return <em>the maximum amount of money the thief can rob <strong>without alerting the police</strong></em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/10/rob1-tree.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [3,2,3,null,3,null,1]</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong> Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/10/rob2-tree.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [3,4,5,1,3,null,1]</p>
<p><strong>Output:</strong> 9</p>
<p><strong>Explanation:</strong> Maximum amount of money the thief can rob = 4 + 5 = 9.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the tree is in the range <code>[1, 10<sup>4</sup>]</code>.</li>
<li><code>0 <= Node.val <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
rob
-