The most simple solution


#1

public class Solution {
public int solve(ArrayList<ArrayList> A) {
int n = A.size();
int m = A.get(0).size();
int[][] arr = new int[n][m];
for(int i = 0; i<n ;i++)
{
for(int j = 0;j<m;j++)
{
arr[i][j] = A.get(i).get(j);
}
}
int[][] dp = new int[n+1][m+1];
int ans = Integer.MIN_VALUE;
for(int i = n-1;i>=0;i–)
{
for(int j = m-1;j>=0;j–)
{
dp[i][j] = arr[i][j]+(dp[i+1][j]+dp[i][j+1]-dp[i+1][j+1]);
ans = Math.max(ans,dp[i][j]);
}
}
return ans;
}
}