House Robber
Solution ApproachWas this helpful?
Medium•array•Expected: O(n) time, O(n) space
dynamic-programming
Problem
Given an array representing money in each house, return the maximum amount you can rob without robbing two adjacent houses.
Example 1:
Input: nums = [1, 2, 3, 1]
Output: 4
Explanation: Rob house 1 (money=1) and house 3 (money=3). Total = 1 + 3 = 4.
Example 2:
Input: nums = [2, 7, 9, 3, 1]
Output: 12
Explanation: Rob house 1 (money=2), house 3 (money=9), house 5 (money=1). Total = 12.
Reference solution unlocks after your first submission
Loading...
