dp
of size n x n
where n
is the length of the input array nums
.dp
array with the values of nums
, since when the subarray length is 1, the score difference is the number itself.n
, fill in the dp
array by considering subarrays nums[i...j]
.nums[i...j]
, calculate the score difference for two scenarios: taking the leftmost element (nums[i] - dp[i+1][j]
) or the rightmost element (nums[j] - dp[i][j-1]
).dp[i][j]
with this value.dp
array, check if dp[0][n-1]
is greater than or equal to 0. If it is, return true
, indicating that Player 1 can win; otherwise, return false
.