博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
House Robber
阅读量:4074 次
发布时间:2019-05-25

本文共 1170 字,大约阅读时间需要 3 分钟。

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.

Credits:
Special thanks to  for adding this problem and creating all test cases. Also thanks to  for adding additional test cases.

Java代码:

public class Solution {    public int rob(int[] num) {        int len = num.length;        if(0 == len)            return 0;        if(1 == len)            return num[0];        if(2 == len)            return num[0]>num[1]?num[0]:num[1];        int[] val = new int[len];        val[0] = num[0];        val[1] = num[1];        val[2] = num[2]+val[0];        for(int i =3;i
val[i-3]?(val[i-2]+num[i]):(val[i-3]+num[i]); } return val[len-1]>val[len-2]?val[len-1]:val[len-2]; }}
 

转载地址:http://gpuni.baihongyu.com/

你可能感兴趣的文章
字节跳动后端开发一面
查看>>
CentOS Tensorflow 基础环境配置
查看>>
centOS7安装FTP
查看>>
FTP的命令
查看>>
CentOS操作系统下安装yum的方法
查看>>
ping 报name or service not known
查看>>
FTP 常见问题
查看>>
zookeeper单机集群安装
查看>>
do_generic_file_read()函数
查看>>
Python学习笔记之数据类型
查看>>
Python学习笔记之特点
查看>>
shell 快捷键
查看>>
VIM滚屏操作
查看>>
EMC 2014存储布局及十大新技术要点
查看>>
linux内核内存管理(zone_dma zone_normal zone_highmem)
查看>>
将file文件内容转成字符串
查看>>
循环队列---数据结构和算法
查看>>
优先级队列-数据结构和算法
查看>>
链接点--数据结构和算法
查看>>
servlet中请求转发(forword)与重定向(sendredirect)的区别
查看>>