# Easy-题目26：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.

dp[n]=max(dp[n-1],dp[n-2]+money[n])

int rob(int* nums, int numsSize) {
if(numsSize==0)
return 0;
if(numsSize==1)
return nums[0];
else if(numsSize==2)
return nums[0]>nums[1]?nums[0]:nums[1];
else
{
int i;
int dp1,dp2,dp;

dp1=nums[0];
dp2=nums[0]>nums[1]?nums[0]:nums[1];
for(i=2;i<numsSize;i++)
{
dp=dp2>dp1+nums[i]?dp2:dp1+nums[i];
dp1=dp2;
dp2=dp;
}
return dp;
}
}

0ms，beats3.60%，众数0ms，96.40%
Cmershen的碎碎念：

• 本文已收录于以下专栏：

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