✅Accepted Java Code || O(n^2)
Complexity\n- Time complexity : O(n^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity : O(n^2)\n Add your space complexity here, e.g. O(n) \n
# Complexity\n- Time complexity : $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int maxScore(List<List<Integer>> grid) {\n        int res = 0;\n        \n        \n        int n = grid.size();\n        int m = grid.get(0).size();\n        int[][] A = new int[n][m];\n        \n        for(int i = 0; i < n; i++){\n            List<Integer> arr = grid.get(i);\n            for(int j = 0; j < m; j++)\n                A[i][j] = arr.get(j);\n        }\n        \n        int[][] dp = new int[n][m];\n        // dp[0] = \n        \n        int result = Integer.MIN_VALUE;\n        for(int j = 1; j < m; j++){\n            dp[0][j] = Math.max(0, dp[0][j - 1]);\n            dp[0][j] -= A[0][j - 1];\n            dp[0][j] += A[0][j];\n            if(result < dp[0][j])\n                result = dp[0][j];\n        }\n        for(int i = 1; i < n; i++){\n            dp[i][0] = Math.max(0, dp[i - 1][0]);\n            dp[i][0] -= A[i - 1][0];\n            dp[i][0] += A[i][0];\n            if(result < dp[i][0])\n                result = dp[i][0];\n        }\n        \n        for(int i = 1; i < n; i++){\n            for(int j = 1; j < m; j++){\n                int num1 = Math.max(0, dp[i][j - 1]);\n                num1 -= A[i][j - 1];\n                int num2 = Math.max(0, dp[i - 1][j]);\n                num2 -= A[i - 1][j];\n                \n                dp[i][j] = Math.max(num1, num2) + A[i][j];\n                if(result < dp[i][j])\n                    result = dp[i][j];\n            }\n        }\n        \n        return result;\n    }\n}\n```
['Java']