# 【Leetcode 198】关关的刷题日记69 – Leetcode 198 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 {public:
int rob(vector<int>& nums) {
int n=nums.size();
if(n==0)
return 0;
if(n==1)
return nums[0];
if(n==2)
return max(nums[0], nums[1]);
int temp1=nums[0], temp2=max(nums[0],nums[1]), re;
for(int i=2; i<n; i++)
{
re=max(temp1+nums[i],temp2);
temp1=temp2;
temp2=re;
}
return re;
}};```

0 条评论

• ### 关关的刷题日记05 —— Leetcode 217. Contains Duplicate 方法1和方法2

题目 Leetcode 217. Contains Duplicate Given an array of integers, find if the arra...

• ### 【Leetcode 303】关关的刷题日记67–Leetcode 303 Range Sum Query – Immutable

关关的刷题日记67 – Leetcode 303 Range Sum Query – Immutable 题目 Given an integer array n...

• ### 关关的刷题日记12——Leetcode 189. Rotate Array 方法1、2、3

关小刷刷题12 – Leetcode 189. Rotate Array 方法1、2、3 题目 Rotate an array of n elements to...

• ### Golang洗牌算法

主要思路为每次随机挑选一个值，放在数组末尾。然后在n-1个元素的数组中再随机挑选一个值，放在数组末尾，以此类推。注意，一定要设置随机种子，否则每次返回的值是一样...

• ### 【LeetCode每日一题】26. Remove Duplicates from Sorted Array

Given a sorted array nums, remove the duplicates in-place such that each element...

• ### Leetcode【31、162】

这道题是给一个数组，表示一个排列。求比当前排列大的下一个排列。如果没有则返回最小排列。

• ### Message Pool分析

Android中，我们在线程之间通信传递通常採用Android的消息机制，而这机制传递的正是Message。

• ### Python爬虫获取豆瓣TOP250电影详情

偶然间看到豆瓣电影的TOP250榜单，于是突发奇想写了这个爬虫脚本。将通过爬取豆瓣电影TOP250的榜单列表获取电影详情页的URL，然后再爬取电影详情页URL中...

• ### BAT码农的刷题日记01——高效面试算法题 | 逆序数为K的排列数量 629. K Inverse Pairs Array

高效面试算法题 | 逆序数为K的排列数量 629. K Inverse Pairs Array ================================...