题目描述链接:https://leetcode-cn.com/problems/predict-the-winner/
解题基本思路:递归
LeetCode C++ 解题代码:
class Solution { public: bool PredictTheWinner(vector<int>& nums) { return total(nums,0,nums.size()-1,1)>=0; } int total(vector<int>& nums,int start,int end,int turn){ if(start==end){ return nums[start]*turn; } int total_start=nums[start]*turn+total(nums,start+1,end,-turn); int total_end=nums[end]*turn+total(nums,start,end-1,-turn); return max(total_start*turn,total_end*turn)*turn; } };