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.

代码:

public class HouseRobber {

    public static void main(String[] args) {
int[] money = {12,23,5,2,434,57,4,767,4,2};
int maximum = houseRobber(money);
System.out.println(maximum);
} private static int houseRobber(int[] num) {
if (0 == num.length) {
return 0;
}
else if (1 == num.length) {
return num[0];
}
else {
num[1] = Math.max(num[0], num[1]);
for (int i = 2; i < num.length; i++) {
num[i] = Math.max(num[i-1], num[i-2] + num[i]); //这里没有想到
}
}
return num[num.length-1];
} }

  

House Robber的更多相关文章

  1. [LeetCode] House Robber III 打家劫舍之三

    The thief has found himself a new place for his thievery again. There is only one entrance to this a ...

  2. [LeetCode] House Robber II 打家劫舍之二

    Note: This is an extension of House Robber. After robbing those houses on that street, the thief has ...

  3. [LeetCode] House Robber 打家劫舍

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

  4. 【leetcode】House Robber

    题目简述 You are a professional robber planning to rob houses along a street. Each house has a certain a ...

  5. LeetCode House Robber III

    原题链接在这里:https://leetcode.com/problems/house-robber-iii/ 题目: The thief has found himself a new place ...

  6. Leetcode House Robber II

    本题和House Robber差不多,分成两种情况来解决.第一家是不是偷了,如果偷了,那么最后一家肯定不能偷. class Solution(object): def rob(self, nums): ...

  7. Leetcode 198 House Robber

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

  8. Java for LeetCode 213 House Robber II

    Note: This is an extension of House Robber. After robbing those houses on that street, the thief has ...

  9. 【leetcode】House Robber & House Robber II(middle)

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

  10. [LintCode] House Robber II 打家劫舍之二

    After robbing those houses on that street, the thief has found himself a new place for his thievery ...

随机推荐

  1. the last lecture

    2008.07.25,CMU教授Randy Pausch教授因癌症去世,仅47岁. 几年之前,当我看到Pausch先生最后一课的视频时,让我震撼. 转眼之间,7年过去了,这7年,让我成长了许多. 7年 ...

  2. IplImage, CvMat, Mat 的关系

    IplImage, CvMat, Mat 的关系 转载来源:http://www.cnblogs.com/summerRQ/articles/2406109.html opencv中常见的与图像操作有 ...

  3. mac上创建MySQL的基本步骤

    首先得安装环境与MySQL的软件 安装环境的软件在这里我用的是:jdk-8u111-macosx-x64.dmg MySQL:mysql-5.7.16-osx10.11-x86_64.dmg 安装好了 ...

  4. 运行在linux上的mysql常用命令

    mysql的注释:--或者# 1.mysql服务进程的命令 service mysqld start;#启动mysql服务 service mysqld status;#查看服务状态 service ...

  5. MOB 短信验证

    工具/原料   Android Studio mob SDK中的jar 和.so文件 方法/步骤   1 把3个jar 放入libs   并添加依赖 在项目的build.gradle里面   在你的项 ...

  6. MVVM模式下实现拖拽

    在文章开始之前先看一看效果图 我们可以拖拽一个"游戏"给ListBox,并且ListBox也能接受拖拽过来的数据, 但是我们不能拖拽一个"游戏类型"给它. 所以 ...

  7. HTML5 重要标签及其属性学习

    1.google字体:<link href="https://fonts.googleapis.com/css?family=Lobster" rel="style ...

  8. maven 各种用途

    1.maven 管理项目编译 作为项目编译代码管理工具,可以方便的进行编译集成. 2. maven 扩展单元测试 扩展对接junit可以方便进行单元测试 3.maven profiles各种devel ...

  9. js-js实现,在HTML中使用JavaScript,基本概念

    Js实现: 1.JavaScript实现的组成: 核心(ECMAScript):由ECMA-262定义,提供核心语言功能 文档对象模型(DOM)提供访问和操作网页内容的方法以及接口 浏览器对象模型(B ...

  10. 解决js小数求和出现多位小数问题

    在小数相加时,可能会产生多个小数位.如下所示: var x=1+1;   //2 var x=1.20+1.11;   //2.31 var x=1.56+1.76;   //3.3200000000 ...