臭道人

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

 

posted on 2021-02-19 01:42  臭总  阅读(12)  评论(0编辑  收藏  举报

导航