# 198. House Robber [easy] (Python)

## 题目链接

https://leetcode.com/problems/house-robber/

## 题目原文

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.

## 思路方法

### 思路一

class Solution(object):
def rob(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) == 0:
return 0
elif len(nums) < 2:
return max(nums[0], nums[-1])
money = [0]*len(nums)
money[0], money[1] = nums[0], max(nums[0], nums[1])
for i in xrange(2, len(nums)):
money[i] = max(nums[i] + money[i-2], money[i-1])
return money[len(nums)-1]

### 思路二

class Solution(object):
def rob(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
now = last = 0
for i in nums:
last, now = now, max(i+last, now)
return now

PS: 新手刷LeetCode，新手写博客，写错了或者写的不清楚还请帮忙指出，谢谢！

## 198. House Robber Leetcode Python

You are a professional robber planning to rob houses along a street. Each house has a certain amount...

## LeetCode#198. House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount...

## 198. House Robber

leetcode 198 - Easy

## LeetCode动态规划198. House Robber思路解析

LeetCode动态规划198. House Robber思路解析，用最容易理解的递归解释

举报原因： 您举报文章：198. House Robber [easy] (Python) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)