JAVA MEMO
\n# Code\njava []\nclass Solution {\n  int[][] dp;\n  public int maxOperations(int[] nums) {\n    if(nums.length < 2) return 0;\n    int n = nums.length;\n    d
\n# Code\n```java []\nclass Solution {\n  int[][] dp;\n  public int maxOperations(int[] nums) {\n    if(nums.length < 2) return 0;\n    int n = nums.length;\n    dp = new int[n][n];\n\n    int a = 1 + dfs(nums, 2, n - 1, nums[0] + nums[1]); \n    int b = 1 + dfs(nums, 1, n - 2, nums[0] + nums[n - 1]); \n    int c = 1 + dfs(nums, 0, n - 3, nums[n - 1] + nums[n - 2]); \n\n    return Math.max(Math.max(a,b),c);\n  }\n\n  public int dfs(int[] nums, int left, int right, int sum) {\n    if(right - left < 1) return 0;\n    if(dp[left][right] != 0) return dp[left][right];\n\n    int a = 0, b = 0, c = 0;\n    if(nums[left] + nums[left+1] == sum) a = 1 + dfs(nums, left + 2, right, sum);\n    if(nums[left] + nums[right] == sum) b = 1 + dfs(nums, left + 1, right - 1, sum);\n    if(nums[right] + nums[right - 1] == sum) c = 1 + dfs(nums, left, right - 2, sum);\n\n    return dp[left][right] = Math.max(Math.max(a,b),c);\n  }\n}\n\n```
['Java']