Press "Enter" to skip to content

花花酱 LeetCode 198. House Robber

Problem:

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 system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

Idea:

DP

Time complexity: O(n)

Space complexity: O(n) -> O(1)

Solution:

C++ / Recursion + Memorization

Time complexity: O(n)

Space complexity: O(n)

 

C++ / DP

Time complexity: O(n)

Space complexity: O(n)

C++ / O(1) Space

 

请尊重作者的劳动成果,转载请注明出处!花花保留对文章/视频的所有权利。
如果您喜欢这篇文章/视频,欢迎您捐赠花花。
If you like my articles / videos, donations are welcome.

Buy anything from Amazon to support our website
您可以通过在亚马逊上购物(任意商品)来支持我们

Paypal
Venmo
huahualeetcode
微信打赏

Be First to Comment

Leave a Reply