Predict the Winner
MediumArray
Description
You are given an integer array nums. Two players take turns picking from either end of the array. The player with more points wins. Return true if Player 1 can win (or tie). Both players play optimally.
Examples
Input:
nums = [1,5,2]Output:
falseExplanation:
Player 2 wins with optimal play.
Input:
nums = [1, 5, 2]Output:
falseExplanation:
Given nums = [1, 5, 2], the condition does not hold: Player 1 can win (or tie).
Input:
nums = [1, 5, 233, 7]Output:
trueExplanation:
Given nums = [1, 5, 233, 7], the condition holds: Player 1 can win (or tie).
Constraints
- •
1 ≤ nums.length ≤ 20 - •
0 ≤ nums[i] ≤ 10^7