You are given an integer array nums.
Two players are playing a game with this array: Player 1 and Player 2.
Player 1 and Player 2 take turns, with Player 1 starting first. Both players start the game with a score of 0.
At each turn, the current player takes the number at either end of the array (i.e., nums[0] or nums[nums.length - 1]), removing it from the array and adding it to their own score. The game ends when there are no more elements in the array.
Return true if Player 1's final score is greater than or equal to Player 2's final score, and false otherwise.
Note that a tie counts as a win for Player 1. You may assume that both players play optimally.
Example 1:
Input: nums = [1,5,2]
Output: false
Explanation:
[5,2]. Player 2 takes 5, leaving 2 for Player 1.[1,5]. Player 2 takes 5, leaving 1 for Player 1.1 + 2 = 3 and Player 2 finishes with 5. Player 1 can never win, so return false.Example 2:
Input: nums = [1,5,233,7]
Output: true
Explanation:
[5,233,7]. Player 2 must then choose between 5 and 7, and no matter which number Player 2 chooses, Player 1 can take 233 on the next turn.true.
Constraints:
1 <= nums.length <= 200 <= nums[i] <= 107