Leetcode Title: House robber

Source: Internet
Author: User

House robber:

You is a professional robber planning to rob houses along a street. Each house have a certain amount of money stashed, the only constraint stopping all from robbing each of the them are that Adjac ENT houses have security system connected and it would automatically contact the police if the adjacent houses were broken Into on the same night.

Given a list of non-negative integers representing the amount of money in each house, determine the maximum amount of mone Y you can rob tonight without alerting the police.

classSolution { Public:    intRob (vector<int>&nums) {        //The coll array is used to hold the maximum value that the house of the former I can Rob.vector<int>Coll; intSize =nums.size (); if(0==size)return 0; if(1==size)returnnums[0]; //Initialize ConditionColl.push_back (nums[0]); Coll.push_back (nums[0] > nums[1] ? nums[0]: nums[1]); //Beforethe maximum value that house can rob to can be constructed according to Coll[i-1], coll[i-2], Nums[i]         for(inti =2; i < size; ++i) Coll.push_back (max (Coll[i-1], Coll[i-2] +nums[i])); returnColl[size-1];    }}; 

Leetcode title: House robber

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.