Getting stackoverflow error


#1

public class Solution {
public int adjacent(ArrayList<ArrayList> A) {
int n=A.get(0).size();
int[][] dp=new int[2][n];
boolean[][] vis=new boolean[2][n];
int ans = fun(A,0,0,vis,dp,n);
return ans;
}
public int fun(ArrayList<ArrayList> A,int r,int c,boolean[][] vis,int dp[][],int n){
if(r>1||c>n-1)
return 0;
if(vis[r][c]==true)
return dp[r][c];
vis[r][c]=true;
int ans1=A.get®.get©;
if(A.get®.get©>0&&c+2<n){
ans1+=fun(A,0,c+2,vis,dp,n);
}
int ans=0;
if(r==0);
ans=Math.max(fun(A,(r+1),c,vis,dp,n),Math.max(fun(A,r,c+1,vis,dp,n),fun(A,(r+1),c+1,vis,dp,n)));

    dp[r][c]=Math.max(ans,ans1);
    return dp[r][c];
}

}