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.
Public classSolution { Public intRobint[] nums) { //Note the meaning of the intermediate variable: Unrob means that the house is not stolen at the moment. Rob says the house has been stolen now. intRobbed=0; intUnrobbed=0; intRes=0; for(inti=0;i<nums.length;i++){ inttemp=unrobbed; Unrobbed=Math.max (unrobbed,robbed); Robbed=nums[i]+temp; } returnMath.max (unrobbed,robbed); }}
[Leedcode 198] House robber