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