publicintdfs(int l, int r, int[] nums){ if (dp[l][r] != 0) return dp[l][r]; if (l == r) return dp[l][r] = nums[l]; return dp[l][r] = Math.max(nums[l] - dfs(l + 1, r, nums), nums[r] - dfs(l, r - 1, nums)); }
publicbooleanPredictTheWinner(int[] nums){ int n = nums.length; for (int i = 0; i < nums.length; i++) { Arrays.fill(dp[i], 0); } return dfs(0, n - 1, nums) >= 0; } }