198. House Robber
# Easy
Solution 1: regular sequence DP array.
robs[x] means the max money can rob in
house [0:x]Initialize
robs[0]androbs[1]. Initialize as much as possible.Time complexity = , spcase complexity =

Solution 2: optimize space complexity, because the previous robs are not useful
Only
robs[x-2]androbs[x-1]are used for computingrobs[x].Initialization is important.
Time complexity = , space complexity =

Last updated
Was this helpful?