House Robber
Example
Challenge
public class Solution { /**
@param A: An array of non-negative integers
@return: The maximum amount of money you can rob tonight */ public long houseRobber(int[] A) { // write your code here
// if(A.length == 0 || A == null){ // return 0; // }
// long[] dp = new long[A.length+1];
// dp[0] = A[0];
// if(A.length > 1){
// dp[1] = Math.max(A[0],A[1]);
// }
// for (int i = 2; i < A.length ;i++ ){
// dp[i] = Math.max(A[i]+dp[i-2],dp[i-1]);
// }
return dp[A.length-1];
Last updated