Class Solution

java.lang.Object
g0101_0200.s0198_house_robber.Solution

public class Solution extends Object
198 - House Robber.<p>Medium</p> <p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and <strong>it will automatically contact the police if two adjacent houses were broken into on the same night</strong>.</p> <p>Given an integer array <code>nums</code> representing the amount of money of each house, return <em>the maximum amount of money you can rob tonight <strong>without alerting the police</strong></em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,1]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <pre><code> Rob house 1 (money = 1) and then rob house 3 (money = 3). Total amount you can rob = 1 + 3 = 4. </code></pre> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [2,7,9,3,1]</p> <p><strong>Output:</strong> 12</p> <p><strong>Explanation:</strong></p> <pre><code> Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1). Total amount you can rob = 2 + 9 + 1 = 12. </code></pre> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 100</code></li> <li><code>0 <= nums[i] <= 400</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • rob

      public int rob(int[] nums)