Test cases
|
|
Solution 1: accepted 0ms
DP: To calculate the total gain after robbing house number N, we need to consider the accumulated stash of house N-2 or N-3. N-1 is not available as it will trigger the alarm.
Time: O(n)
Or convert to Space O(1) by storing two previous stashes in two int variables.
Solution 2: accepted 0ms
More elegant code.