当前位置:网站首页>House raiding
House raiding
2022-06-13 02:33:00 【Prodigal son's private dishes】
subject :
You are a professional thief , Plan to steal houses along the street . There is a certain amount of cash in every room , The only restriction on your theft is that adjacent houses are equipped with interconnected anti-theft systems , If two adjacent houses are broken into by thieves on the same night , The system will automatically alarm .
Given an array of non negative integers representing the storage amount of each house , Count you Without triggering the alarm , The maximum amount that can be stolen overnight .
Example 1:
Input :[1,2,3,1]
Output :4
explain : Steal 1 House No ( amount of money = 1) , And then steal 3 House No ( amount of money = 3).
Maximum amount stolen = 1 + 3 = 4 .
Example 2:
Input :[2,7,9,3,1]
Output :12
explain : Steal 1 House No ( amount of money = 2), Steal 3 House No ( amount of money = 9), Then steal 5 House No ( amount of money = 1).
Maximum amount stolen = 2 + 9 + 1 = 12 .
Code :
class Solution {
public int rob(int[] nums) {
if(nums == null || nums.length == 0){
return 0;
}
if(nums.length == 1){
return nums[0];
}
int[] dp = new int[nums.length+1];
dp[0] = nums[0];
dp[1] = Math.max(nums[0], nums[1]);
for(int i = 2; i < nums.length; i++){
dp[i] = Math.max(dp[i-1], dp[i-2] + nums[i]);
}
return dp[nums.length - 1];
}
}
边栏推荐
- Think: when do I need to disable mmu/i-cache/d-cache?
- too old resource version,Code:410
- Superficial understanding of conditional random fields
- [keras] generator for 3D u-net source code analysis py
- Jump model between mirrors
- 03 认识第一个view组件
- A real-time target detection model Yolo
- ROS learning -5 how function packs with the same name work (workspace coverage)
- Matlab: find the inner angle of n-sided concave polygon
- Opencvsharp4 pixel read / write and memory structure of color image and gray image
猜你喜欢
![Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]](/img/39/d5c4d424a160635791c4645d6f2e10.png)
Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]

How can intelligent safe power distribution devices reduce the occurrence of electrical fire accidents?

智能安全配电装置如何减少电气火灾事故的发生?

L1 regularization and its sparsity

03 recognize the first view component
![[reading papers] comparison of deeplobv1-v3 series, brief review](/img/80/714b8e5b2ad31b0a1a0b8320a3c714.jpg)
[reading papers] comparison of deeplobv1-v3 series, brief review

Paper reading - jukebox: a generic model for music

Huffman tree and its application

Chapter7-10_ Deep Learning for Question Answering (1/2)

拍拍贷母公司信也季报图解:营收24亿 净利5.3亿同比降10%
随机推荐
redis. Conf general configuration details
Barrykay electronics rushes to the scientific innovation board: it is planned to raise 360million yuan. Mr. and Mrs. Wang Binhua are the major shareholders
Basic exercise of test questions decimal to hexadecimal
Jump model between mirrors
[reading papers] deep learning face representation by joint identification verification, deep learning applied to optimization problems, deepid2
redis 多个服务器共用一个
Surpass the strongest variant of RESNET! Google proposes a new convolution + attention network: coatnet, with an accuracy of 89.77%!
[pytorch] kaggle large image dataset data analysis + visualization
Sans certificate generation
[reading paper] generate confrontation network Gan
Linear, integer, nonlinear, dynamic programming
Introduction to easydl object detection port
[51nod.3210] binary Statistics (bit operation)
Solution of depth learning for 3D anisotropic images
Opencvshare4 and vs2019 configuration
ROS learning-6 detailed explanation of publisher programming syntax
Opencv 9 resize size change rotate rotate blur mean (blur)
Matlab: find the inner angle of n-sided concave polygon
Introduction to armv8/armv9 - learning this article is enough
Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]