其他分享
首页 > 其他分享> > 2.19

2.19

作者:互联网

https://leetcode-cn.com/problems/predict-the-winner/submissions/

预测赢家

①暴力递归

class Solution {
public:
   bool PredictTheWinner(vector<int>& nums) {
        return total(nums, 0, nums.size() - 1) >= 0;
    }
    int total(vector<int>&nums,int i,int j)
    {
        if(i==j)
            return nums[i];
    int    left=nums[i]-total(nums,i+1,j);
    int    right=nums[j]-total(nums,i,j-1);
        return max(left,right);
    }
};
View Code

 

标签:right,return,nums,int,vector,2.19,total
来源: https://www.cnblogs.com/chouhui/p/14414296.html