public int rob(TreeNode root){
  int[] res=dfs(root);
  return Math.max(res[0],res[1]);
}

public int rob ( TreeNode root ) { int [ ] res = dfs ( root ) ; return Math . max ( res [ 0 ] , res [ 1 ] ) ; }
if current house is robbed , then subtrees ' roots cannot be robbed . the maximum is root . val + rob ( root . left . left ) + rob ( root . left . right ) + rob ( root . right . left ) + rob ( root . right . right ) if current house is robbed , then subtrees ' roots can be robbed . the maximum is rob ( root . left ) + rob ( root . right ) the base case is where we don ' t need to calculate sub problems . when root is null in our case . just return 0 .
